Note: This blog post is still a work in progress. Right now it's mostly
ramblings of a madman, I'm still trying to organizing my thoughts about this.
All uppercase bolded variables are vectors in R3.
Drawing
Let R(t)=Q+tD be a ray originating at Q,
in the direction of D. We can describe a cube of radius r centered
at C with the equation
∣∣C−P∣∣∞=r
With P a vector in R3. To be more specific: P is a
point on the square if it satisfies the above equation for the given
C and r.
If we want to know if (and where) a ray R(t) intersects a given cube. We can
substitute P in for R(t)
∣∣C−R(t)∣∣∞∣∣C−Q+tD∣∣∞=r=r
But now by definition of the infinity
norm, we can write
∣∣C−Q+tD∣∣∞=max{∣Cx−Qx+tDx∣,∣Cy−Qy+tDy∣,∣Cz−Qz+tDz∣}=r
Here, since we're looking for a t that will satisfy this equation, we can
solve for it element-wise. That is, we can look at the expression for x
∣Cx−Qx+tDx∣Cx−Qx+tDxt=r=±r=(Qx−Cx±r)/Dx
This gives us two values for t which we can then plug back into the three
expressions above. If either value t∗ is a maximum, then R(t∗) a
point on the square. We do this same process for the y and z expressions,
finding six separate values for t, and expecting zero, one, or two solutions.
See also