I have a plane class that stores a plane as
Vector position;
Vector normal;
float d;
(Vector is just x,y,z in a helper class)
Been using it for years, serves almost all my purposes. However, I use it as a savant without really thinking much about how/why it works.
So... I need to convert it to to a float[4] format for a friend to use for some OpenGL rendering. What's the right way to convert point/normal/d to the plane equation in float[4]? Everything I try seems to be off a little bit.
[Edit] This is the plane's Create() function, which assigns a value to d...
void Create(Vector thePoint, Vector theNormal)
{
theNormal.Normalize();
pos=thePoint;
normal=theNormal;
d=-theNormal.Dot(thePoint);
}
Using homogeneous coordinates points are
Point = [x,y,z,1]
To define the equation of a plane
you need the following 4 values for the coordinates of the plane
Plane = [n_x,n_y,n_z,-d]
Where (n_x,n_y,n_z)
is the normal vector, and d
the distance to the origin.
Now taking the dot product of the point and the plane yields the equation
[x,y,z,1] . [n_x,n_y,n_z,-d] = 0
x*n_x + y*n_y + z*n_z - d = 0
In C#
code this is
public float[] GetCoord(Plane plane)
{
return new float[] { plane.normal.X, plane.normal.Y, plane.normal.Z, -plane.d };
}