|
vector1 = point2 - point1
vector2 = point3 - point1
We then do the cross product on the two vectors and come up with only one vector. The calculation for this is done as follows:
vector3.x = (vector1.y * vector2.z) - (vector1.z * vector2.y);
vector3.y = (vector1.z * vector2.x) - (vector1.x * vector2.z);
vector3.z = (vector1.x * vector2.y) - (vector1.y * vector2.x);
Now the only thing left to do is make sure the length is one, which is called normalizing. We first get the current length of the vector and then divide each axis by the length:
length = sqrt((vector3.x)² + (vector3.y)² + (vector3.z)²);
normal.x = vector3.x / length;
normal.y = vector3.y / length;
normal.z = vector3.z / length;
As stated above, to calculate the distance of the point from the plane the dot product of the normal and the point have to be calculated using (normal.x * point.x) + (normal.y * point.y) + (normal.z * point.z).
The value will indicate the distance from the plane to the point. If the value is negative then the point is in front, while if negative it is behind and if zero - it is on the plane. It follows that to calculate if a collision occurs anywhere on the plane, a look at if the sign changes will provide the information needed.