Distance of a plane

52 Views Asked by At

I have posted this question in Stack Overflow programming forum. Someone there feels it might be more suited to Mathematics.

I have to warn you I am rusty in math and was terrible in Algebra.

Using Accord Framework plane class. The help on this page specifies a constructor that creates a plane a certain distance from the origin. I am getting numbers that do not make sense. If I create a plane using the vector 5,5,5 at a distance of 1 then I would expect the plane to be 1 away from the origin:

        Plane p = new Plane(new Vector3(5,5,5),1);
        Console.WriteLine("{0}", p.DistanceToPoint(new Point3(0,0,0)));

Instead I get the value of 0.115470053837925.

The only way I get a distance that makes sense is to create a plane using one of the three constructors below:

        Plane p = new Plane(new Vector3(0,0,1),1);
        Plane p = new Plane(new Vector3(0,1,0),1);
        Plane p = new Plane(new Vector3(1,0,0),1);

When using any of these constructors I get a distance of 1 from the origin.

What am I missing here?

2

There are 2 best solutions below

1
On BEST ANSWER

Either the API or the documentation are wrong.

Regardless the other arguments, Offset is deemed to specify the distance from the plane to the origin, and DistanceToPoint should return the same value.


I strongly suspect that Offset is in reality the parameter d of the equation, and the normal vector is never normalized. Indeed,

$$5x+5y+5z+1=0$$

defines a plane at distance $\dfrac1{5\sqrt3}$ of the origin.


Try with

Vector3 v= new Vector3(5, 5, 5); v.Normalize();
Plane p = new Plane(v, 1);
1
On

The generic plane equation can be written as

$$ (p-p_0)\cdot \vec n = 0 $$

with $p = (x,y,z)$ In our case

$$ \vec n = (5,5,5) =5\sqrt 3\left( \frac{1}{\sqrt 3}(1,1,1)\right) $$

where $\frac{1}{\sqrt 3}(1,1,1) = \frac{\vec n}{||\vec n||}$ Choosing a plane at a distance $d$ from the origin means that

$$ p_0 = d\frac{\vec n}{||\vec n||} = 1\times \frac{1}{\sqrt 3}(1,1,1) $$

so the sought plane is

$$ (p - 1\times \frac{1}{\sqrt 3}(1,1,1))\cdot (5,5,5) = 0 $$

or

$$ 5x+5y+5z-5\sqrt 3 = 0 $$

0r

$$ x+y+z-\sqrt 3 = 0 $$