Line–line intersection

Line–line intersection

In Euclidean geometry, the intersection of a line and a line can be the empty set, a point, or a line. Distinguishing these cases and finding the intersection point have use, 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 are called skew lines and have no point of intersection. If they are in the same plane 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.
Intersection of two lines
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 Skew lines § Testing for skewness.
Given two points on each line
The determinants can be written out as:
(where t and u are real numbers). The intersection point of the lines is found with one of the following values of t or u:
with:
The intersection point falls within the first line segment if 0.0 ≤ t ≤ 1.0, and it falls within the second line segment if 0.0 ≤ u ≤ 1.0. These inequalities can be tested without dividing for t, allowing rapid determination of the existence of any line segment intersection before calculating its exact point.[2]
When the two lines are parallel or coincident the denominator is zero:
If the lines are almost parallel, then a computer solution might encounter numeric problems implementing the solution described above: the recognition of this condition might require an approximate test in a practical application. An alternate approach might be to rotate the line segments so that one of them is horizontal, whence the solution of the rotated parametric form of the second line is easily obtained. Careful discussion of the special cases is required (parallel lines/coincident lines, overlapping/non-overlapping intervals).
Given the equations of the lines
and so,
To find the y coordinate, all we need to do is substitute the value of x into either one of the two line equations, for example, into the first:
Hence, the point of intersection is
Note if a = b then the two lines are parallel. If c ≠ d as well, the lines are different and there is no intersection, otherwise the two lines are identical.
Using homogeneous coordinates
n-line intersection
Existence of and expression for the intersection
In two dimensions
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.
where now A is 2n × 3 and b is 2n × 1. As before there is a unique intersection point if and only if A has full column rank and the augmented matrix [A | b ] does not, and the unique intersection if it exists is given by
Nearest point to non-intersecting lines
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
which is the unit vector along the line, rotated by 90 degrees.
And so the squared distance from a point, x, 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 x and set the result equal to the zero vector:
so
and so
In three dimensions
where I is the identity matrix, and so[4]
See also
Line segment intersection
Line intersection in projective space
Distance from a point to a line
Parallel postulate
Intersection (Euclidean geometry) § Two line segments