Line–line intersection
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 [1] 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.Template:Further explanation needed
Formulas
Script error: No such module "Labelled list hatnote".
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 Template:Slink.
Given two points on each line
First we consider the intersection of two lines L1Script error: No such module "Check for unknown parameters". and L2Script error: No such module "Check for unknown parameters". in two-dimensional space, with line L1Script error: No such module "Check for unknown parameters". being defined by two distinct points (x1, y1)Script error: No such module "Check for unknown parameters". and (x2, y2)Script error: No such module "Check for unknown parameters"., and line L2Script error: No such module "Check for unknown parameters". being defined by two distinct points (x3, y3)Script error: No such module "Check for unknown parameters". and (x4, y4)Script error: No such module "Check for unknown parameters"..[2]
The intersection Template:Mvar of line L1Script error: No such module "Check for unknown parameters". and L2Script error: No such module "Check for unknown parameters". can be defined using determinants.
The determinants can be written out as:
When the two lines are parallel or coincident, the denominator is zero.
Given two points on each line segment
Script error: No such module "Labelled list hatnote".
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 L1Script error: No such module "Check for unknown parameters". and L2Script error: No such module "Check for unknown parameters". in terms of first degree Bézier parameters:
(where Template:Mvar and Template:Mvar are real numbers). The intersection point of the lines is found with one of the following values of Template:Mvar or Template:Mvar, where
and
with
There will be an intersection if 0 ≤ t ≤ 1Script error: No such module "Check for unknown parameters". and 0 ≤ u ≤ 1Script error: No such module "Check for unknown parameters".. The intersection point falls within the first line segment if 0 ≤ t ≤ 1Script error: No such module "Check for unknown parameters"., and it falls within the second line segment if 0 ≤ u ≤ 1Script error: No such module "Check for unknown parameters".. 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.[3]
In the case where the two line segments share an x axis and , and simplify to with
Given two line equations
Script error: No such module "Labelled list hatnote".
The Template:Mvar and Template:Mvar 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 y = ax + cScript error: No such module "Check for unknown parameters". and y = bx + dScript error: No such module "Check for unknown parameters". where Template:Mvar and Template:Mvar are the slopes (gradients) of the lines and where Template:Mvar and Template:Mvar are the Template:Mvar-intercepts of the lines. At the point where the two lines intersect (if they do), both Template:Mvar coordinates will be the same, hence the following equality:
We can rearrange this expression in order to extract the value of Template:Mvar,
and so,
To find the Template:Mvar coordinate, all we need to do is substitute the value of Template:Mvar into either one of the two line equations, for example, into the first:
Hence, the point of intersection is
Note that if a = bScript error: No such module "Check for unknown parameters". then the two lines are parallel and they do not intersect, unless c = dScript error: No such module "Check for unknown parameters". as well, in which case the lines are coincident and they intersect at every point.
Using homogeneous coordinates
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 (x, y, w)Script error: No such module "Check for unknown parameters".. The mapping from 3D to 2D coordinates is (x′, y′) = (Template:Sfrac, Template:Sfrac)Script error: No such module "Check for unknown parameters".. We can convert 2D points to homogeneous coordinates by defining them as (x, y, 1)Script error: No such module "Check for unknown parameters"..
Assume that we want to find intersection of two infinite lines in 2-dimensional space, defined as a1x + b1y + c1 = 0Script error: No such module "Check for unknown parameters". and a2x + b2y + c2 = 0Script error: No such module "Check for unknown parameters".. We can represent these two lines in line coordinates as U1 = (a1, b1, c1)Script error: No such module "Check for unknown parameters". and U2 = (a2, b2, c2)Script error: No such module "Check for unknown parameters".. The intersection P′Script error: No such module "Check for unknown parameters". of two lines is then simply given by[4]
If cp = 0Script error: No such module "Check for unknown parameters"., the lines do not intersect.
More than two lines
Script error: No such module "Labelled list hatnote".
The intersection of two lines can be generalized to involve additional lines. The existence of and expression for the Template:Mvar-line intersection problem are as follows.
In two dimensions
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 Template:Mvarth equation (i = 1, …, nScript error: No such module "Check for unknown parameters".) as
and stack these equations into matrix form as
where the Template:Mvarth row of the n × 2Script error: No such module "Check for unknown parameters". matrix AScript error: No such module "Check for unknown parameters". is [ai1, ai2]Script error: No such module "Check for unknown parameters"., wScript error: No such module "Check for unknown parameters". is the 2 × 1 vector [Script error: No such module "Su".]Script error: No such module "Check for unknown parameters"., and the Template:Mvarth element of the column vector bScript error: No such module "Check for unknown parameters". is biScript error: No such module "Check for unknown parameters".. If AScript error: No such module "Check for unknown parameters". has independent columns, its rank is 2. Then if and only if the rank of the augmented matrix [A | b]Script error: No such module "Check for unknown parameters". is also 2, there exists a solution of the matrix equation and thus an intersection point of the Template:Mvar lines. The intersection point, if it exists, is given by
where AgScript error: No such module "Check for unknown parameters". is the Moore–Penrose generalized inverse of AScript error: No such module "Check for unknown parameters". (which has the form shown because AScript error: No such module "Check for unknown parameters". has full column rank). Alternatively, the solution can be found by jointly solving any two independent equations. But if the rank of AScript error: No such module "Check for unknown parameters". 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.
In three dimensions
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
Thus a set of Template:Mvar lines can be represented by 2nScript error: No such module "Check for unknown parameters". equations in the 3-dimensional coordinate vector wScript error: No such module "Check for unknown parameters".:
where now AScript error: No such module "Check for unknown parameters". is 2n × 3Script error: No such module "Check for unknown parameters". and bScript error: No such module "Check for unknown parameters". is 2n × 1Script error: No such module "Check for unknown parameters".. As before there is a unique intersection point if and only if AScript error: No such module "Check for unknown parameters". has full column rank and the augmented matrix [A | b]Script error: No such module "Check for unknown parameters". does not, and the unique intersection if it exists is given by
Nearest points to skew lines
Script error: No such module "Labelled list hatnote".
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 two dimensions
In the two-dimensional case, first, represent line Template:Mvar as a point piScript error: No such module "Check for unknown parameters". on the line and a unit normal vector n̂iScript error: No such module "Check for unknown parameters"., perpendicular to that line. That is, if x1Script error: No such module "Check for unknown parameters". and x2Script error: No such module "Check for unknown parameters". are points on line 1, then let p1 = x1Script error: No such module "Check for unknown parameters". and let
which is the unit vector along the line, rotated by a right angle.
The distance from a point xScript error: No such module "Check for unknown parameters". to the line (p, n̂)Script error: No such module "Check for unknown parameters". is given by
And so the squared distance from a point xScript error: No such module "Check for unknown parameters". to a line is
The sum of squared distances to many lines is the cost function:
This can be rearranged:
To find the minimum, we differentiate with respect to xScript error: No such module "Check for unknown parameters". and set the result equal to the zero vector:
so
and so
In more than two dimensions
While n̂iScript error: No such module "Check for unknown parameters". is not well-defined in more than two dimensions, this can be generalized to any number of dimensions by noting that n̂i n̂iTScript error: No such module "Check for unknown parameters". 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 piScript error: No such module "Check for unknown parameters". and another point giving the distance to the line. In any number of dimensions, if v̂iScript error: No such module "Check for unknown parameters". is a unit vector along the Template:Mvarth line, then
- becomes
where IScript error: No such module "Check for unknown parameters". is the identity matrix, and so[5]
General derivation
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 aiScript error: No such module "Check for unknown parameters". and a unit direction vector n̂iScript error: No such module "Check for unknown parameters".. The square of the distance from a point pScript error: No such module "Check for unknown parameters". to one of the lines is given from Pythagoras:
where (p − ai)T n̂iScript error: No such module "Check for unknown parameters". is the projection of p − aiScript error: No such module "Check for unknown parameters". on line Template:Mvar. The sum of distances to the square to all lines is
To minimize this expression, we differentiate it with respect to pScript error: No such module "Check for unknown parameters"..
which results in
where IScript error: No such module "Check for unknown parameters". is the identity matrix. This is a matrix Sp = CScript error: No such module "Check for unknown parameters"., with solution p = S+CScript error: No such module "Check for unknown parameters"., where S+Script error: No such module "Check for unknown parameters". is the pseudo-inverse of SScript error: No such module "Check for unknown parameters"..
Non-Euclidean geometry
Script error: No such module "Labelled list hatnote".Script error: No such module "Unsubst".
In spherical geometry, any two great circles intersect.[6]
In hyperbolic geometry, given any line and any point, there are infinitely many lines through that point that do not intersect the given line.[6]
See also
- Line segment intersection
- Line intersection in projective space
- Distance between two parallel lines
- Distance from a point to a line
- Line–plane intersection
- Parallel postulate
- Triangulation (computer vision)
- Template:Slink
References
External links
- Distance between Lines and Segments with their Closest Point of Approach, applicable to two, three, or more dimensions.