Suppose you have a line defined by two 3-dimensional points and a plane defined by three 3-dimensional points. How do you tell where the line intersects the plane?

## Step 1: Convert the plane into an equation

The equation of a plane is of the form Ax + By + Cz = D.

To get the coefficients A, B, C, simply find the cross product of the two vectors formed by the 3 points. This will give you a vector that is normal to the triangle. The components of this vector are, coincidentally, the coefficients A, B, and C.

Let's call the 3 points in the plane Q, R, and S.

QR = <R_{x} - Q_{x}, R_{y} - Q_{y}, R_{z} - Q_{z}>

QS = <S_{x} - Q_{x}, S_{y} - Q_{y}, S_{z} - Q_{z}>

QR × QS = Normal Vector N.

A = N_{x}

B = N_{y}

C = N_{z}

Ax + Bx + Cx = 0 is the equation of the line with a similar tilt but shifted such that it goes through the origin (0, 0, 0). To get the value of D, shift the equation with one of the Q, R, S points.

A(x - Q_{x}) + B(y - Q_{y}) + C(z - Q_{z}) = 0

You now have a Ax + By + Cz = D equation.

## Step 2: Find the equation for the line

Suppose your two points are A and B (different A and B from the plane)

P(t) = A + (B - A) * t

This equation can be broken up into 3 equations for each component of the vector:

x = A_{x} + (B_{x} - A_{x}) * t

y = A_{y} + (B_{y} - A_{y}) * t

z = A_{z} + (B_{z} - A_{z}) * t

## Step 3: Combine them and solve for t

Now you have definitions of x, y, and z in terms of a variable t. Plug these equations in for the values of x, y, and z in the equation for the plane, and solve for t. Once you get a value for t, plug it back into the equation for the line, and you'll have your point of intersection.

## Potential Error/Edge Cases

To get the coefficients A, B, C, simply find the cross product of the two vectors formed by the 3 points. This will give you a vector that is normal to the triangle. The components of this vector are, coincidentally, the coefficients A, B, and C.

Let's call the 3 points in the plane Q, R, and S.

QR = <R

QS = <S

QR × QS = Normal Vector N.

A = N

B = N

C = N

Ax + Bx + Cx = 0 is the equation of the line with a similar tilt but shifted such that it goes through the origin (0, 0, 0). To get the value of D, shift the equation with one of the Q, R, S points.

A(x - Q

You now have a Ax + By + Cz = D equation.

P(t) = A + (B - A) * t

This equation can be broken up into 3 equations for each component of the vector:

x = A

y = A

z = A

- If the 3 points are in a line rather than being a valid description of a unique plane, then the normal vector will have coefficients of 0.
- If the line does not intersect the plane or if the line is in the plane, then plugging the equations for the line into the equation of the plane will result in an expression where t is canceled out of it completely. If the resulting expression is correct (like 0 = 0) then the line is part of the plane. Otherwise, the line is parallel with the plane.