Ray-Plane Intersection

A plane is defined by the equation: Ax + By + Cz + D = 0, or the vector [A B C D]. A, B, and C, define the normal to the plane. If A2 + B2 + C2 = 1 then the unit normal Pn = [A B C]. If A, B, and C define a unit normal, then the distance from the origin [0 0 0] to the plane is D.

A ray is defined by: R(t) = R0 + t * Rd , t > 0
 with                R0 = [X0, Y0, Z0]
	             Rd = [Xd, Yd, Zd]
To determine if there is an intersection with the plane, substitute for R(t) into the plane equation and get:
A(X0 + Xd * t) + B(Y0 + Yd * t) + C(Z0 + Zd * t) + D = 0

which yields:
t = -(A*X0 + B*Y0 + C*Z0 + D) / (A*Xd + B*Yd + C*Zd)
  = -(Pn·R0 + D) / (Pn·Rd)
First compute Pn·Rd = Vd. If Vd = 0 (incident angle, q = 90 degrees) then the ray is parallel to the plane and there is no intersection (if ray is in the plane then we ignore it). If Vd > 0 then the normal of the plane is pointing away from the ray. If we use one-sided planar objects then could stop if Vd > 0, else continue. Now compute second dot product: V0 = -(Pn·R0 + D) and compute t = V0 / Vd. If t < 0 then the ray intersects plane behind origin, i.e., no intersection of interest, else compute intersection point:

Pi = [Xi Yi Zi] = [X0 + Xd * t Y0 + Yd * t Z0 + Zd * t]

Now we usually want surface normal for the surface facing the ray, so if Vd > 0 (normal facing away) then reverse sign of ray.

So algorithm analysis:
1. Compute Vd and compare to 0: 3 "*"s, 2 "+"s, 1 comparison.
2. Compute V0 and t and compare to 0: 3 or 4 "*"s, 3 "+"s, 1 comparison.
3. Compute intersection joint: 3 "*"s, 3 "+"s.
4. Compare Vprd to 0 and reverse normal: 1 comparison.
Total = 10 "*"s, 8 "+"s, 3 comparisons.