Plane constructors inconsistent
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 7.8k
- Forks
- 1.2k
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 49
Description
Release Type: Official Release
Version: All versions up to the latest (4.2.0.2381 as of this issue)
Platform(s): All (tested on Windows)
Describe the bug
From #2670, I believe according to the documentation:
The distance of the plane along its normal from the origin. means positive 'D' moves in the positive direction of its normal vector.`
This would imply Plane.D represents the plane equation in the form P.N = d instead of P.N + d = 0
This line of thinking is true for the following constructor:
var p = new Vector3(0, 1, 0);
var normal = new Vector3(0, 1, 0);
var plane = new Plane(p, normal);
System.Diagnostics.Debug.WriteLine($"Normal: {plane.Normal}, D: {plane.D}");
This returns
Normal: X:0 Y:1 Z:0, D: 1
However, the following constructor returns the wrong 'D' value (three points sitting on Y = 1, made in anticlockwise direction)
var p1 = new Vector3(-1, 1, -1);
var p2 = new Vector3(-1, 1, 1);
var p3 = new Vector3(1, 1, 1);
var plane = new Plane(p1, p2, p3);
System.Diagnostics.Debug.WriteLine($"Normal: {plane.Normal}, D: {plane.D}");
This returns
Normal: X:0 Y:1 Z:0, D: -1
I have changed the three points to clockwise (to double check anticlockwise is the correct way to get the plane pointing up):
var p1 = new Vector3(-1, 1, -1);
var p2 = new Vector3(-1, 1, 1);
var p3 = new Vector3(1, 1, 1);
var plane = new Plane(p1, p3, p2);
System.Diagnostics.Debug.WriteLine($"Normal: {plane.Normal}, D: {plane.D}");
This returns
Normal: X:0 Y:-1 Z:0, D: 1
This confirms the three points should be anticlockwise to make the normal point "outwards", but D is now flipped.
Expected behavior
In my opinion, my thinking is D: 1 is the correct value, but I am doubting myself now, so now need confirmation from others.
Additional context
Related to #2670
Unfortunately, System.Numerics also follows the same issue with the three points (assuming this is an issue)
https://github.com/dotnet/runtime/blob/1d1bf92fcf43aa6981804dc53c5174445069c9e4/src/libraries/System.Private.CoreLib/src/System/Numerics/Plane.cs#L62
Their documentation also states
D represents The distance of the plane along its normal from the origin.
so now I'm doubting which way the plane equation is supposed to be.
EDIT:
Some poor dev in the past also casting doubt:
https://github.com/stride3d/stride/blob/975c8a8ea55cf2ab20a64a32a261eb62d6922bce/sources/engine/Stride.Rendering/Rendering/SortModeDistance.cs#L42
https://github.com/stride3d/stride/blob/975c8a8ea55cf2ab20a64a32a261eb62d6922bce/sources/engine/Stride.Rendering/Rendering/VisibilityGroup.cs#L117
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by comparing the Plane constructors and their documentation with the related discussion in #2670. Review sources/engine/Stride.Rendering/Rendering/SortModeDistance.cs and VisibilityGroup.cs, plus the linked System.Numerics implementation, to establish the intended plane equation and sign convention. Done means the convention is decided and the constructor, documentation, and affected usages agree.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- computer-graphics, game-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100