3

I'm writing some geometry code using System.Numerics and I seem to have encountered a bug in the implementation of the Plane.CreateFromVertices method. The comment on Plane.D says:

The plane's distance from the origin along its normal vector.

However if I call this with three vertices at Y = 0.5 I get the plane:

N = (0, 1, 0)
D = -0.5

The D is negative! So as far as I can see either the comment is wrong, and D should be labelled:

The distance of the origin from the plane along the normal vector

or Plane.CreateFromVertices is wrong, and D should be positive.

Am I correct (in which case I shall go write a bug report), or am I misunderstanding something here (in which case, what and why?).

Martin
  • 12,469
  • 13
  • 64
  • 128

1 Answers1

1

You are correct. The documentation is misleading. For example I compare two different math libraries. System.Numerics and Accord.Math

    public void RightHandRulePlane_Accord()
    {
        {
            var plane = System.Numerics.Plane.CreateFromVertices
                (
                 new System.Numerics.Vector3( 0, 0.5f, 0 )
                 , new System.Numerics.Vector3( 1, 0.5f, 0 )
                 , new System.Numerics.Vector3( 0, 0.5f, 1 ) );

            Console.WriteLine( plane.ToString() );

            plane = System.Numerics.Plane.CreateFromVertices
                (
                 new System.Numerics.Vector3( 0, 0.5f, 1 )
                 , new System.Numerics.Vector3( 1, 0.5f, 0 )
                 , new System.Numerics.Vector3( 0, 0.5f, 0 )
                );

            Console.WriteLine( plane.ToString() );

        }
        {
            var plane = Accord.Math.Plane.FromPoints
                (
                 new Accord.Math.Point3( 0, 0.5f, 0 )
                 , new Accord.Math.Point3( 1, 0.5f, 0 )
                 , new Accord.Math.Point3( 0, 0.5f, 1 ) );

            Console.WriteLine( plane.ToString() );

            plane = Accord.Math.Plane.FromPoints
                (
                 new Accord.Math.Point3( 0, 0.5f, 1 )
                 , new Accord.Math.Point3( 1, 0.5f, 0 )
                 , new Accord.Math.Point3( 0, 0.5f, 0 )
                );

            Console.WriteLine( plane.ToString() );
        }
    }

the output is

{Normal:<0, -1, 0> D:0.5}
{Normal:<0, 1, 0> D:-0.5}
0x -1y 0z +0.5 = 0
0x +1y 0z -0.5 = 0

The signed value +0.5 is the constant term in the equation

ax + by + cz + d = 0

You are correct in that you probably should read that as the distance from the plane origin to the coordinate system origin in the direction of the plane normal.

bradgonesurfing
  • 30,949
  • 17
  • 114
  • 217
  • What I'm asking about is the wording of the definition. you say: `The D value should be distance in the direction of the normal from the origin` so I read that as *starting* at the origin, how far along the normal to the plane. But then the output you show is the opposite of that i.e. it's the distance starting at the plane and going *to* the origin. Am I just reading this wrong? – Martin Jul 13 '17 at 13:30
  • Actually you have a good point and are correct. I've updated my answer with an experiment from another library that clarifies what is going on. – bradgonesurfing Jul 13 '17 at 13:54