Line–plane intersection



In analytic geometry, the intersection of a line and a plane in three-dimensional space can be the empty set, a point, or a line. It is the entire line if that line is embedded in the plane, and is the empty set if the line is parallel to the plane but outside it. Otherwise, the line cuts through the plane at a single point.

Distinguishing these cases, and determining equations for the point and line in the latter cases, have use in computer graphics, motion planning, and collision detection.

Algebraic form
In vector notation, a plane can be expressed as the set of points $$\mathbf{p}$$ for which
 * $$(\mathbf{p}-\mathbf{p_0})\cdot\mathbf{n} = 0$$

where $$\mathbf{n}$$ is a normal vector to the plane and $$\mathbf{p_0}$$ is a point on the plane. (The notation $$\mathbf{a}\cdot\mathbf{b}$$ denotes the dot product of the vectors $$\mathbf{a}$$ and $$\mathbf{b}$$.)

The vector equation for a line is
 * $$\mathbf{p} = \mathbf{l_0} + \mathbf{l}\ d \quad   d\in\mathbb{R}$$

where $$\mathbf{l}$$ is a unit vector in the direction of the line, $$\mathbf{l_0}$$ is a point on the line, and $$d$$ is a scalar in the real number domain. Substituting the equation for the line into the equation for the plane gives
 * $$((\mathbf{l_0} + \mathbf{l}\ d) - \mathbf{p_0})\cdot\mathbf{n} = 0.$$

Expanding gives
 * $$(\mathbf{l}\cdot\mathbf{n})\ d + (\mathbf{l_0}-\mathbf{p_0})\cdot\mathbf{n} = 0.$$

And solving for $$d$$ gives
 * $$d = {(\mathbf{p_0}-\mathbf{l_0})\cdot\mathbf{n} \over \mathbf{l}\cdot\mathbf{n}}.$$

If $$\mathbf{l}\cdot\mathbf{n} = 0$$ then the line and plane are parallel. There will be two cases: if $$(\mathbf{p_0}-\mathbf{l_0})\cdot\mathbf{n} =0$$ then the line is contained in the plane, that is, the line intersects the plane at each point of the line. Otherwise, the line and plane have no intersection.

If $$\mathbf{l}\cdot\mathbf{n} \ne 0$$ there is a single point of intersection. The value of $$d$$ can be calculated and the point of intersection, $$\mathbf{p}$$, is given by
 * $$\mathbf{p} = \mathbf{l_0} + \mathbf{l}\ d$$.

Parametric form
A line is described by all points that are a given direction from a point. A general point on a line passing through points $$\mathbf{l}_a=(x_a, y_a, z_a)$$ and $$\mathbf{l}_b=(x_b, y_b, z_b)$$ can be represented as


 * $$\mathbf{l}_a + \mathbf{l}_{ab} t, \quad t\in \mathbb{R},$$

where $$\mathbf{l}_{ab}=\mathbf{l}_b - \mathbf{l}_a$$ is the vector pointing from $$\mathbf{l}_a$$ to $$\mathbf{l}_b$$.

Similarly a general point on a plane determined by the triangle defined by the points $$\mathbf{p}_0=(x_0, y_0, z_0)$$, $$\mathbf{p}_1=(x_1, y_1, z_1)$$ and $$\mathbf{p}_2=(x_2, y_2, z_2)$$ can be represented as


 * $$\mathbf{p}_0 + \mathbf{p}_{0 1} u + \mathbf{p}_{0 2} v, \quad u,v\in\mathbb{R},$$

where $$\mathbf{p}_{0 1} = \mathbf{p}_1 - \mathbf{p}_0$$ is the vector pointing from $$\mathbf{p}_0$$ to $$\mathbf{p}_1$$, and $$\mathbf{p}_{0 2} = \mathbf{p}_2 - \mathbf{p}_0$$ is the vector pointing from $$\mathbf{p}_0$$ to $$\mathbf{p}_2$$.

The point at which the line intersects the plane is therefore described by setting the point on the line equal to the point on the plane, giving the parametric equation:
 * $$\mathbf{l}_a + \mathbf{l}_{ab} t = \mathbf{p}_0 + \mathbf{p}_{0 1} u + \mathbf{p}_{0 2} v.$$

This can be rewritten as
 * $$\mathbf{l}_a - \mathbf{p}_0 = - \mathbf{l}_{ab} t + \mathbf{p}_{0 1} u + \mathbf{p}_{0 2} v,$$

which can be expressed in matrix form as
 * $$ \begin{bmatrix} \mathbf{l}_a - \mathbf{p}_0 \end{bmatrix} = \begin{bmatrix} - \mathbf{l}_{ab} & \mathbf{p}_{0 1} & \mathbf{p}_{0 2} \end{bmatrix} \begin{bmatrix} t \\ u \\ v \end{bmatrix}, $$

where the vectors are written as column vectors.

This produces a system of linear equations which can be solved for $$t$$, $$u$$ and $$v$$. If the solution satisfies the condition $$t \in [0,1],$$, then the intersection point is on the line segment between $$\mathbf{l}_a$$ and $$\mathbf{l}_b$$, otherwise it is elsewhere on the line. Likewise, if the solution satisfies $$u,v \in [0,1],$$, then the intersection point is in the parallelogram formed by the point $$\mathbf{p}_0$$ and vectors $$\mathbf{p}_{0 1}$$ and $$\mathbf{p}_{0 2}$$. If the solution additionally satisfies $$(u+v) \leq 1$$, then the intersection point lies in the triangle formed by the three points $$\mathbf{p}_0$$, $$\mathbf{p}_1$$ and $$\mathbf{p}_2$$.

The determinant of the matrix can be calculated as
 * $$\det(\begin{bmatrix} - \mathbf{l}_{ab} & \mathbf{p}_{0 1} & \mathbf{p}_{0 2} \end{bmatrix}) = -\mathbf{l}_{ab} \cdot (\mathbf{p}_{0 1} \times \mathbf{p}_{0 2}).$$

If the determinant is zero, then there is no unique solution; the line is either in the plane or parallel to it.

If a unique solution exists (determinant is not 0), then it can be found by inverting the matrix and rearranging:
 * $$ \begin{bmatrix} t \\ u \\ v \end{bmatrix} = \begin{bmatrix} - \mathbf{l}_{ab} & \mathbf{p}_{0 1} & \mathbf{p}_{0 2} \end{bmatrix}^{-1} \begin{bmatrix} \mathbf{l}_a - \mathbf{p}_0 \end{bmatrix},$$

which expands to
 * $$ \begin{bmatrix} t \\ u \\ v \end{bmatrix} = \frac{1}{-\mathbf{l}_{ab} \cdot (\mathbf{p}_{0 1} \times \mathbf{p}_{0 2})} \begin{bmatrix} {(\mathbf{p}_{0 1} \times \mathbf{p}_{0 2})}^\mathrm{T} \\ {(\mathbf{p}_{0 2} \times -\mathbf{l}_{ab})}^\mathrm{T} \\ {(-\mathbf{l}_{ab} \times \mathbf{p}_{0 1})}^\mathrm{T} \end{bmatrix} \begin{bmatrix} \mathbf{l}_a - \mathbf{p}_0 \end{bmatrix}$$

and then to
 * $$ \begin{bmatrix} t \\ u \\ v \end{bmatrix} = \frac{1}{-\mathbf{l}_{ab} \cdot (\mathbf{p}_{0 1} \times \mathbf{p}_{0 2})} \begin{bmatrix} {(\mathbf{p}_{0 1} \times \mathbf{p}_{0 2})} \cdot (\mathbf{l}_a - \mathbf{p}_0) \\ {(\mathbf{p}_{0 2} \times -\mathbf{l}_{ab})} \cdot (\mathbf{l}_a - \mathbf{p}_0) \\ {(-\mathbf{l}_{ab} \times \mathbf{p}_{0 1})} \cdot (\mathbf{l}_a - \mathbf{p}_0) \end{bmatrix},$$

thus giving the solutions:
 * $$t = \frac{{(\mathbf{p}_{0 1} \times \mathbf{p}_{0 2})} \cdot (\mathbf{l}_a - \mathbf{p}_0)}{-\mathbf{l}_{ab} \cdot (\mathbf{p}_{0 1} \times \mathbf{p}_{0 2})}$$
 * $$u = \frac{{(\mathbf{p}_{0 2} \times -\mathbf{l}_{ab})} \cdot (\mathbf{l}_a - \mathbf{p}_0)}{-\mathbf{l}_{ab} \cdot (\mathbf{p}_{0 1} \times \mathbf{p}_{0 2})}$$
 * $$v = \frac{{(-\mathbf{l}_{ab} \times \mathbf{p}_{0 1})} \cdot (\mathbf{l}_a - \mathbf{p}_0)}{-\mathbf{l}_{ab} \cdot (\mathbf{p}_{0 1} \times \mathbf{p}_{0 2})}.$$

The point of intersection is then equal to
 * $$\mathbf{l}_a + \mathbf{l}_{ab}t$$

Uses
In the ray tracing method of computer graphics a surface can be represented as a set of pieces of planes. The intersection of a ray of light with each plane is used to produce an image of the surface. In vision-based 3D reconstruction, a subfield of computer vision, depth values are commonly measured by so-called triangulation method, which finds the intersection between light plane and ray reflected toward camera.

The algorithm can be generalised to cover intersection with other planar figures, in particular, the intersection of a polyhedron with a line.