From Wikipedia, the free encyclopedia - View original article

(Redirected from 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.

The number and locations of possible intersections between two lines and the number of possible lines with no intersections (parallel) with a given line are the distinguishing features of non-Euclidean geometry.

First we consider the intersection of two lines and in 2-dimensional space, with line being defined by two distinct points and , and line being defined by two distinct points and .^{[1]}

The intersection of line and can be defined using determinants.

The determinants can be written out as:

Note that the intersection point is for the infinitely long lines defined by the points, rather than the line segments between the points, and can produce an intersection point beyond the lengths of the line segments. If (rather than solving for the point in a single step), the solution in terms of first degree Bézier parameters is first found, then this intermediate result can be checked for 0.0 ≤ *t* ≤ 1.0 and 0.0 ≤ *u* ≤ 1.0 (where *t* and *u* are the driving variables).

When the two lines are parallel or coincident the denominator term is zero:

If the lines are very close to being parallel, then a computer solution may encounter numeric problems in the solution described above, and so recognition of this condition may require an appropriately "fuzzy" test in practical application. A more robust and general solution may be obtained by rotation of the line segments to drive one of them 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).

In two dimensions, more than two lines almost certainly do not intersect at a single point. Similarly, in three or more dimensions, even two lines almost certainly do not intersect; pairs of lines that do not intersect are called skew lines. However, 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 *i* 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

which is the unit vector along the line, rotated by 90 degrees.

Note that the distance from a point, *x* to the line is given by

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

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 *i*th line, then

- becomes

where *I* is the identity matrix, and so

^{[citation needed]}

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 *y*-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:

- .

We can rearrange this expression in order to extract the value of ,

- ,

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.

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). The mapping from 3D to 2D coordinates is (x,y) = (X/W, Y/W). 2D points can be converted to homogeneous coordinates by defining them as (x,y,1). Thus, the implicit equation of a line can be given in homogeneous coordinates as:

We can do a similar operation with the cross product to get the intersection of 2 lines:

This returns the intersection point in homogeneous coordinates. In the special case of W = 0, we say that the intersection point is at infinity. This means the lines are parallel. As an aside, the implicit coefficients of a line can be obtained by the cross product of two points:

- Line segment intersection
- Line intersection in projective space
- Distance from a point to a line
- Parallel postulate

**^**"Weisstein, Eric W. "Line-Line Intersection." From MathWorld".*A Wolfram Web Resource*. Retrieved 2008-01-10.

- Distance between Lines and Segments with their Closest Point of Approach, applicable to two, three, or more dimensions.