The
plane3d template has a constructor to do exactly what you want, and the
triangle3d template has an accessor for the same thing... just use them.
Code: Select all
// use the triangle accessor
plane3df p = tri.getPlane();
// or use the plane3d constructor
plane3df p (tri.pointA, tri.pointB, tri.pointC);
If you follow the code, you'll see the calculation of the plane is as follows
Code: Select all
p.Normal = (tri.pointB - tri.pointA).crossProduct(tri.pointC - tri.pointA);
p.Normal.normalize();
p.D = -tri.pointA.dotProduct(p.Normal);
As mentioned previously, just stay away from the member data and use the class functionality provided and you don't have to worry about how to calculate
D.
That said,
D is supposed to be the distance from the origin to the plane (according to the comment in
plane3d.h), but it is really the distance from the nearest point on the plane to the origin...
Code: Select all
vector3d<T> getMemberPoint() const
{
return Normal * -D;
}
Travis