In Euclidean geometry, the intersection of a line and a line can be the empty set, a point, or another line. Distinguishing these cases and finding the intersection have uses, for example, in computer graphics, motion planning, and collision detection.
In three-dimensional Euclidean geometry, if two lines are not in the same plane, they have no point of intersection and are called skew lines. If they are in the same plane, however, there are three possibilities: if they coincide (are not distinct lines), they have an infinitude of points in common (namely all of the points on either of them); if they are distinct but have the same slope, they are said to be parallel and have no points in common; otherwise, they have a single point of intersection.
The distinguishing features of non-Euclidean geometry are the number and locations of possible intersections between two lines and the number of possible lines with no intersections (parallel lines) with a given line.
A necessary condition for two lines to intersect is that they are in the same plane - that is, are not skew lines. Satisfaction of this condition is equivalent to the tetrahedron with vertices at two of the points on one line and two of the points on the other line being degenerate in the sense of having zero volume. For the algebraic form of this condition, see .
First we consider the intersection of two lines and in two-dimensional space, with line being defined by two distinct points and, and line being defined by two distinct points and .
The intersection of line and can be defined using determinants.
Px=
\begin{vmatrix | |
\begin{vmatrix} |
x1&y1\\x2&y2\end{vmatrix}&\begin{vmatrix}x1&1\\x2&1\end{vmatrix}\\\ \begin{vmatrix}x3&y3\\x4&y4\end{vmatrix}&\begin{vmatrix}x3&1\\x4&1\end{vmatrix}\end{vmatrix}} {\begin{vmatrix}\begin{vmatrix}x1&1\\x2&1\end{vmatrix}&\begin{vmatrix}y1&1\\y2&1\end{vmatrix}\\\ \begin{vmatrix}x3&1\\x4&1\end{vmatrix}&\begin{vmatrix}y3&1\\y4&1\end{vmatrix}\end{vmatrix}} Py=
\begin{vmatrix | |
\begin{vmatrix} |
x1&y1\\x2&y2\end{vmatrix}&\begin{vmatrix}y1&1\\y2&1\end{vmatrix}\\\ \begin{vmatrix}x3&y3\\x4&y4\end{vmatrix}&\begin{vmatrix}y3&1\\y4&1\end{vmatrix}\end{vmatrix}} {\begin{vmatrix}\begin{vmatrix}x1&1\\x2&1\end{vmatrix}&\begin{vmatrix}y1&1\\y2&1\end{vmatrix}\\\ \begin{vmatrix}x3&1\\x4&1\end{vmatrix}&\begin{vmatrix}y3&1\\y4&1\end{vmatrix}\end{vmatrix}}
The determinants can be written out as:
\begin{align} Px&=
(x1y2-y1x2)(x3-x4)-(x1-x2)(x3y4-y3x4) | |
(x1-x2)(y3-y4)-(y1-y2)(x3-x4) |
\\[4px] Py&=
(x1y2-y1x2)(y3-y4)-(y1-y2)(x3y4-y3x4) | |
(x1-x2)(y3-y4)-(y1-y2)(x3-x4) |
\end{align}
When the two lines are parallel or coincident, the denominator is zero.
The intersection point above is for the infinitely long lines defined by the points, rather than the line segments between the points, and can produce an intersection point not contained in either of the two line segments. In order to find the position of the intersection in respect to the line segments, we can define lines and in terms of first degree Bézier parameters:
L1=\begin{bmatrix}x1\ y1\end{bmatrix} +t\begin{bmatrix}x2-x1\ y2-y1\end{bmatrix}, L2=\begin{bmatrix}x3\ y3\end{bmatrix} +u\begin{bmatrix}x4-x3\ y4-y3\end{bmatrix}
(where and are real numbers). The intersection point of the lines is found with one of the following values of or, where
t=
\begin{vmatrix | |
x |
1-x3&x3-x4\\y1-y3&y3-y4\end{vmatrix}}{\begin{vmatrix}x1-x2&x3-x4\\y1-y2&y3-y4\end{vmatrix}}=
(x1-x3)(y3-y4)-(y1-y3)(x3-x4) | |
(x1-x2)(y3-y4)-(y1-y2)(x3-x4) |
u=-
\begin{vmatrix | |
x |
1-x2&x1-x3\\y1-y2&y1-y3\end{vmatrix}}{\begin{vmatrix}x1-x2&x3-x4\\y1-y2&y3-y4\end{vmatrix}}=-
(x1-x2)(y1-y3)-(y1-y2)(x1-x3) | |
(x1-x2)(y3-y4)-(y1-y2)(x3-x4) |
,
(Px,Py)=l(x1+t(x2-x1), y1+t(y2-y1)r) or (Px,Py)=l(x3+u(x4-x3), y3+u(y4-y3)r)
There will be an intersection if and . The intersection point falls within the first line segment if, and it falls within the second line segment if . These inequalities can be tested without the need for division, allowing rapid determination of the existence of any line segment intersection before calculating its exact point.[1]
The and coordinates of the point of intersection of two non-vertical lines can easily be found using the following substitutions and rearrangements.
Suppose that two lines have the equations and where and are the slopes (gradients) of the lines and where and are the -intercepts of the lines. At the point where the two lines intersect (if they do), both coordinates will be the same, hence the following equality:
ax+c=bx+d.
We can rearrange this expression in order to extract the value of,
ax-bx=d-c,
x=
d-c | |
a-b |
.
To find the coordinate, all we need to do is substitute the value of into either one of the two line equations, for example, into the first:
y=a
d-c | |
a-b |
+c.
Hence, the point of intersection is
P=\left(
d-c | |
a-b |
,a
d-c | |
a-b |
+c\right).
By using homogeneous coordinates, the intersection point of two implicitly defined lines can be determined quite easily. In 2D, every point can be defined as a projection of a 3D point, given as the ordered triple . The mapping from 3D to 2D coordinates is . We can convert 2D points to homogeneous coordinates by defining them as .
Assume that we want to find intersection of two infinite lines in 2-dimensional space, defined as and . We can represent these two lines in line coordinates as and . The intersection of two lines is then simply given by[2]
P'=(ap,bp,cp)=U1 x U2=(b1c2-b2c1,a2c1-a1c2,a1b2-a2b1)
If, the lines do not intersect.
The intersection of two lines can be generalized to involve additional lines. The existence of and expression for the -line intersection problem are as follows.
In two dimensions, more than two lines almost certainly do not intersect at a single point. To determine if they do and, if so, to find the intersection point, write the th equation as
\begin{bmatrix}ai1&ai2\end{bmatrix}\begin{bmatrix}x\ y\end{bmatrix}=bi,
and stack these equations into matrix form as
Aw=b,
where the th row of the matrix is, is the 2 × 1 vector, and the th element of the column vector is . If has independent columns, its rank is 2. Then if and only if the rank of the augmented matrix is also 2, there exists a solution of the matrix equation and thus an intersection point of the lines. The intersection point, if it exists, is given by
w=Agb=\left(ATA\right)-1ATb,
where is the Moore–Penrose generalized inverse of (which has the form shown because has full column rank). Alternatively, the solution can be found by jointly solving any two independent equations. But if the rank of is only 1, then if the rank of the augmented matrix is 2 there is no solution but if its rank is 1 then all of the lines coincide with each other.
The above approach can be readily extended to three dimensions. In three or more dimensions, even two lines almost certainly do not intersect; pairs of non-parallel lines that do not intersect are called skew lines. But if an intersection does exist it can be found, as follows.
In three dimensions a line is represented by the intersection of two planes, each of which has an equation of the form
\begin{bmatrix}ai1&ai2&ai3\end{bmatrix}\begin{bmatrix}x\ y\ z\end{bmatrix}=bi.
Thus a set of lines can be represented by equations in the 3-dimensional coordinate vector :
Aw=b
where now is and is . As before there is a unique intersection point if and only if has full column rank and the augmented matrix does not, and the unique intersection if it exists is given by
w=\left(ATA\right)-1ATb.
In two or more dimensions, we can usually find a point that is mutually closest to two or more lines in a least-squares sense.
In the two-dimensional case, first, represent line as a point on the line and a unit normal vector, perpendicular to that line. That is, if and are points on line 1, then let and let
\hatn1:=\begin{bmatrix}0&-1\ 1&0\end{bmatrix}
x2-x1 | |
\|x2-x1\| |
which is the unit vector along the line, rotated by a right angle.
The distance from a point to the line is given by
dl(x,(p,\hatn)r)=l|(x-p) ⋅ \hatnr|=\left|(x-p)T\hatn\right|=\left|\hatnT(x-p)\right|=\sqrt{(x-p)T\hatn\hatnT(x-p)}.
And so the squared distance from a point to a line is
dl(x,(p,\hatn)r)2=(x-p)T\left(\hatn\hatnT\right)(x-p).
The sum of squared distances to many lines is the cost function:
E(x)=\sumi
T | |
(x-p | |
i) |
\left(\hatni
T\right) | |
\hatn | |
i |
(x-pi).
This can be rearranged:
\begin{align} E(x)&=\sumixT\hatni
T | |
\hatn | |
i |
x-xT\hatni
T | |
\hatn | |
i |
pi-
T | |
p | |
i |
\hatni
T | |
\hatn | |
i |
x+
T | |
p | |
i |
\hatni
T | |
\hatn | |
i |
pi\\ &=xT\left(\sumi\hatni
T\right) | |
\hatn | |
i |
x-2xT\left(\sumi\hatni
T | |
\hatn | |
i |
pi\right)+\sumi
T | |
p | |
i |
\hatni
T | |
\hatn | |
i |
pi. \end{align}
To find the minimum, we differentiate with respect to and set the result equal to the zero vector:
\partialE(x) | |
\partialx |
=\boldsymbol{0}=2\left(\sumi\hatni
T\right) | |
\hatn | |
i |
x-2\left(\sumi\hatni
T | |
\hatn | |
i |
pi\right)
so
\left(\sumi\hatni
T\right) | |
\hatn | |
i |
x=\sumi\hatni
T | |
\hatn | |
i |
pi
and so
x=\left(\sumi\hatni
T\right) | |
\hatn | |
i |
-1\left(\sumi\hatni
T | |
\hatn | |
i |
pi\right).
While is not well-defined in more than two dimensions, this can be generalized to any number of dimensions by noting that is simply the symmetric matrix with all eigenvalues unity except for a zero eigenvalue in the direction along the line providing a seminorm on the distance between and another point giving the distance to the line. In any number of dimensions, if is a unit vector along the th line, then
\hatni
T | |
\hatn | |
i |
I-\hatvi
T | |
\hatv | |
i |
where is the identity matrix, and so[3]
x=\left(\sumiI-\hatvi
T\right) | |
\hatv | |
i |
-1\left(\sumi\left(I-\hatvi
T | |
\hatv | |
i |
\right)pi\right).
In order to find the intersection point of a set of lines, we calculate the point with minimum distance to them. Each line is defined by an origin and a unit direction vector . The square of the distance from a point to one of the lines is given from Pythagoras:
2 | |
d | |
i |
=\left\|p-ai\right\|2-\left(\left(p-ai\right)T\hatni\right)2 =\left(p-ai\right)T\left(p-ai\right)-\left(\left(p-ai\right)T\hatni\right)2
\sumi
2 | |
d | |
i |
=\sumi\left({\left(p-ai\right)T
To minimize this expression, we differentiate it with respect to .
\sumi\left(2\left(p-ai\right)-2\left(\left(p-ai\right)T\hatni\right)\hatni\right)=\boldsymbol{0}
\sumi\left(p-ai\right)=\sumi\left(\hatni
T | |
\hatn | |
i |
\right)\left(p-ai\right)
which results in
\left(\sumi\left(I-\hatni
T | |
\hatn | |
i |
\right)\right)p =\sumi\left(I-\hatni
T | |
\hatn | |
i |
\right)ai
where is the identity matrix. This is a matrix, with solution, where is the pseudo-inverse of .
See also: Parallel postulate. In spherical geometry, any two great circles intersect.[4]
In hyperbolic geometry, given any line and any point, there are infinitely many lines through that point that do not intersect the given line.