Which side of a plane is a vector

Started by
1 comment, last by GameDev.net 18 years, 7 months ago
I have the following function to return on which side of the plane given by vectors X and Y a vector a is (side "true" or side "false")

bool sideOfPlane(Vector3 a, Vector3 X, Vector3 Y)
{
    Vector3 Z = cross(X, Y);
    Scalar aproj = dot(a, Z);
    if(aproj < 0) return false; else return true;
}
It works, but I wonder, is there a simpler way to do this? Thanks.
Advertisement
The last line can be reduced to return aproj >= 0;, but except for that, if your plane is defined by a pair of base vectors, then your function is already as simple as it can get.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
If you define the plane using a normal and distance from the origin, you can calculate a point on the plane and do the following .... (testpoint - pointonplane) * planenormal .... this will give you the perpendicular distance of the point from the plane

This topic is closed to new replies.

Advertisement