At this point I will add a few posts about basic geometry. This is needed to back up future posts without weighing them down inlining the math. Here is a basic review of planes.
Planes are commonly used for camera logic and are easy to work with as long as the basics are clear.
|Line segment intersecting with a plane.|
I am used to define planes as:
ax + by + cz + d = 0
But feel that the vector form is slightly easier to grasp:
n ᐧ X = d
where n is the normal and the same as (a, b, c) and X is the same as (x, y, z) in the first definition. In the first definition d is the negative of the dot product of the normal and any point in the plane, whereas the second definition d is simply the dot product of the normal with any point in the plane.
Note that n is not necessarily unit length but keeping it unit length can make some operations simpler.
Finding a plane from three points in the plane
Given three points P0, P1 and P2 the plane these points form can be found by taking the cross product of the vectors between the points n = (P1 - P0) ✕ (P2 - P1) if order is counter clockwise or the negative of the cross product if clockwise. The value of d in the vector form definition is the dot product of any point and the normal: d = n ᐧ P0.
Distance between a point and a plane
The distance between a point and a plane is simply the dot product of the normal with the point subtracted by d, which is equivalent of the dot product of the normal and the difference between any point in the plane and the point. Note that the distance is negative if the point is behind the plane:
distance = n ᐧ P - d
Intersection of a line segment and a plane
To find the intersection of a plane and a line segment L0 to L1, simply calculate the distances to the plane using the two endpoints:
d0 = n ᐧ L0 - d
d1 = n ᐧ L1 - d
If d0 and d1 have the same sign then both points are on the same side of the plane and the segment does not intersect, otherwise we can find the intersection point by the relative distance:
P = (d0 / (d0 - d1)) (L1 - L0) + L0
(See illustration above)