Finding the intersection of an infinite ray with a plane in 3D is an important topic in collision detection.



Task

Find the point of intersection for the infinite ray with direction   (0, -1, -1)   passing through position   (0, 0, 10)   with the infinite plane with a normal vector of   (0, 0, 1)   and which passes through [0, 0, 5].




 
plus(U, V) = {U[1] + V[1], U[2] + V[2], U[3] + V[3]}.
 
minus(U, V) = {U[1] - V[1], U[2] - V[2], U[3] - V[3]}.
 
times(U, S) = {U[1] * S, U[2] * S, U[3] * S}.
 
dot(U, V) = U[1] * V[1] + U[2] * V[2] + U[3] * V[3].
 
intersect_point(RayVector, RayPoint, PlaneNormal, PlanePoint) = IntersectPoint =>
    Diff = minus(RayPoint, PlanePoint),
    Prod1 = dot(Diff, PlaneNormal),
    Prod2 = dot(RayVector, PlaneNormal),
    Prod3 = Prod1 / Prod2,
    IntersectPoint = minus(RayPoint, times(RayVector, Prod3)).
 
main =>
    RayVector = {0.0, -1.0, -1.0},
    RayPoint = {0.0, 0.0, 10.0},
    PlaneNormal = {0.0, 0.0, 1.0},
    PlanePoint = {0.0, 0.0, 5.0},
    IntersectPoint = intersect_point(RayVector, RayPoint, PlaneNormal, PlanePoint),
    printf("The ray intersects the plane at (%f, %f, %f)\n",
        IntersectPoint[1],
        IntersectPoint[2],
        IntersectPoint[3]
    ).
 