# 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} \neq 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} _{01}u+\mathbf {p} _{02}v,\quad u,v\in \mathbb {R} ,$
where $\mathbf {p} _{01}=\mathbf {p} _{1}-\mathbf {p} _{0}$ is the vector pointing from $\mathbf {p} _{0}$ to $\mathbf {p} _{1}$, and $\mathbf {p} _{02}=\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} _{01}u+\mathbf {p} _{02}v.$
This can be rewritten as
    $\mathbf {l} _{a}-\mathbf {p} _{0}=-\mathbf {l} _{ab}t+\mathbf {p} _{01}u+\mathbf {p} _{02}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} _{01}&\mathbf {p} _{02}\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} _{01}$ and $\mathbf {p} _{02}$. 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} _{01}&\mathbf {p} _{02}\end{bmatrix}})=-\mathbf {l} _{ab}\cdot (\mathbf {p} _{01}\times \mathbf {p} _{02}).$
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} _{01}&\mathbf {p} _{02}\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} _{01}\times \mathbf {p} _{02})}}{\begin{bmatrix}{(\mathbf {p} _{01}\times \mathbf {p} _{02})}^{\mathrm {T} }\\{(\mathbf {p} _{02}\times -\mathbf {l} _{ab})}^{\mathrm {T} }\\{(-\mathbf {l} _{ab}\times \mathbf {p} _{01})}^{\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} _{01}\times \mathbf {p} _{02})}}{\begin{bmatrix}{(\mathbf {p} _{01}\times \mathbf {p} _{02})}\cdot (\mathbf {l} _{a}-\mathbf {p} _{0})\\{(\mathbf {p} _{02}\times -\mathbf {l} _{ab})}\cdot (\mathbf {l} _{a}-\mathbf {p} _{0})\\{(-\mathbf {l} _{ab}\times \mathbf {p} _{01})}\cdot (\mathbf {l} _{a}-\mathbf {p} _{0})\end{bmatrix}},$
thus giving the solutions:
    $t={\frac {{(\mathbf {p} _{01}\times \mathbf {p} _{02})}\cdot (\mathbf {l} _{a}-\mathbf {p} _{0})}{-\mathbf {l} _{ab}\cdot (\mathbf {p} _{01}\times \mathbf {p} _{02})}}$
    $u={\frac {{(\mathbf {p} _{02}\times -\mathbf {l} _{ab})}\cdot (\mathbf {l} _{a}-\mathbf {p} _{0})}{-\mathbf {l} _{ab}\cdot (\mathbf {p} _{01}\times \mathbf {p} _{02})}}$
    $v={\frac {{(-\mathbf {l} _{ab}\times \mathbf {p} _{01})}\cdot (\mathbf {l} _{a}-\mathbf {p} _{0})}{-\mathbf {l} _{ab}\cdot (\mathbf {p} _{01}\times \mathbf {p} _{02})}}.$
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.