Line–line intersection

From testwiki
Jump to navigation Jump to search

Template:Short description

Two intersecting lines

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

Template:See also

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 Template:Math and Template:Math in two-dimensional space, with line Template:Math being defined by two distinct points Template:Math and Template:Math, and line Template:Math being defined by two distinct points Template:Math and Template:Math.[2]

The intersection Template:Mvar of line Template:Math and Template:Math can be defined using determinants.

Px=||x1y1x2y2||x11x21||x3y3x4y4||x31x41||||x11x21||y11y21||x31x41||y31y41||Py=||x1y1x2y2||y11y21||x3y3x4y4||y31y41||||x11x21||y11y21||x31x41||y31y41||

The determinants can be written out as:

Px=(x1y2y1x2)(x3x4)(x1x2)(x3y4y3x4)(x1x2)(y3y4)(y1y2)(x3x4)[4px]Py=(x1y2y1x2)(y3y4)(y1y2)(x3y4y3x4)(x1x2)(y3y4)(y1y2)(x3x4)

When the two lines are parallel or coincident, the denominator is zero.

Given two points on each line segment

Template:See also

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 Template:Math and Template:Math in terms of first degree Bézier parameters:

L1=[x1y1]+t[x2x1y2y1],L2=[x3y3]+u[x4x3y4y3]

(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

t=|x1x3x3x4y1y3y3y4||x1x2x3x4y1y2y3y4|=(x1x3)(y3y4)(y1y3)(x3x4)(x1x2)(y3y4)(y1y2)(x3x4)

and

u=|x1x2x1x3y1y2y1y3||x1x2x3x4y1y2y3y4|=(x1x2)(y1y3)(y1y2)(x1x3)(x1x2)(y3y4)(y1y2)(x3x4),

with

(Px,Py)=(x1+t(x2x1),y1+t(y2y1))or(Px,Py)=(x3+u(x4x3),y3+u(y4y3))

There will be an intersection if Template:Math and Template:Math. The intersection point falls within the first line segment if Template:Math, and it falls within the second line segment if Template:Math. 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]

Given two line equations

Template:See also

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 Template:Math and Template:Math 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:

ax+c=bx+d.

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

axbx=dc,

and so,

x=dcab.

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:

y=adcab+c.

Hence, the point of intersection is

P=(dcab,adcab+c).

Note that if Template:Math then the two lines are parallel and they do not intersect, unless Template:Math 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 Template:Math. The mapping from 3D to 2D coordinates is Template:Math. We can convert 2D points to homogeneous coordinates by defining them as Template:Math.

Assume that we want to find intersection of two infinite lines in 2-dimensional space, defined as Template:Math and Template:Math. We can represent these two lines in line coordinates as Template:Math and Template:Math. The intersection Template:Math of two lines is then simply given by[4]

P=(ap,bp,cp)=U1×U2=(b1c2b2c1,a2c1a1c2,a1b2a2b1)

If Template:Math, the lines do not intersect.

More than two lines

Template:See also

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 (Template:Math) as

[ai1ai2][xy]=bi,

and stack these equations into matrix form as

𝐀𝐰=𝐛,

where the Template:Mvarth row of the Template:Math matrix Template:Math is Template:Math, Template:Math is the 2 × 1 vector Template:Math, and the Template:Mvarth element of the column vector Template:Math is Template:Math. If Template:Math has independent columns, its rank is 2. Then if and only if the rank of the augmented matrix Template:Math 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

𝐰=𝐀g𝐛=(𝐀𝖳𝐀)1𝐀𝖳𝐛,

where Template:Math is the Moore–Penrose generalized inverse of Template:Math (which has the form shown because Template:Math has full column rank). Alternatively, the solution can be found by jointly solving any two independent equations. But if the rank of Template:Math 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

[ai1ai2ai3][xyz]=bi.

Thus a set of Template:Mvar lines can be represented by Template:Math equations in the 3-dimensional coordinate vector Template:Math:

𝐀𝐰=𝐛

where now Template:Math is Template:Math and Template:Math is Template:Math. As before there is a unique intersection point if and only if Template:Math has full column rank and the augmented matrix Template:Math does not, and the unique intersection if it exists is given by

𝐰=(𝐀𝖳𝐀)1𝐀𝖳𝐛.

Nearest points to skew lines

PQ, the shortest distance between two skew lines AB and CD is perpendicular to both AB and CD

Template:Main

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 Template:Math on the line and a unit normal vector Template:Math, perpendicular to that line. That is, if Template:Math and Template:Math are points on line 1, then let Template:Math and let

𝐧^1:=[0110]𝐱2𝐱1𝐱2𝐱1

which is the unit vector along the line, rotated by a right angle.

The distance from a point Template:Math to the line Template:Math is given by

d(𝐱,(𝐩,𝐧^))=|(𝐱𝐩)𝐧^|=|(𝐱𝐩)𝖳𝐧^|=|𝐧^𝖳(𝐱𝐩)|=(𝐱𝐩)𝖳𝐧^𝐧^𝖳(𝐱𝐩).

And so the squared distance from a point Template:Math to a line is

d(𝐱,(𝐩,𝐧^))2=(𝐱𝐩)𝖳(𝐧^𝐧^𝖳)(𝐱𝐩).

The sum of squared distances to many lines is the cost function:

E(𝐱)=i(𝐱𝐩i)𝖳(𝐧^i𝐧^i𝖳)(𝐱𝐩i).

This can be rearranged:

E(𝐱)=i𝐱𝖳𝐧^i𝐧^i𝖳𝐱𝐱𝖳𝐧^i𝐧^i𝖳𝐩i𝐩i𝖳𝐧^i𝐧^i𝖳𝐱+𝐩i𝖳𝐧^i𝐧^i𝖳𝐩i=𝐱𝖳(i𝐧^i𝐧^i𝖳)𝐱2𝐱𝖳(i𝐧^i𝐧^i𝖳𝐩i)+i𝐩i𝖳𝐧^i𝐧^i𝖳𝐩i.

To find the minimum, we differentiate with respect to Template:Math and set the result equal to the zero vector:

E(𝐱)𝐱=0=2(i𝐧^i𝐧^i𝖳)𝐱2(i𝐧^i𝐧^i𝖳𝐩i)

so

(i𝐧^i𝐧^i𝖳)𝐱=i𝐧^i𝐧^i𝖳𝐩i

and so

𝐱=(i𝐧^i𝐧^i𝖳)1(i𝐧^i𝐧^i𝖳𝐩i).

In more than two dimensions

While Template:Math is not well-defined in more than two dimensions, this can be generalized to any number of dimensions by noting that Template:Math 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 Template:Math and another point giving the distance to the line. In any number of dimensions, if Template:Math is a unit vector along the Template:Mvarth line, then

𝐧^i𝐧^i𝖳 becomes 𝐈𝐯^i𝐯^i𝖳

where Template:Math is the identity matrix, and so[5]

x=(i𝐈𝐯^i𝐯^i𝖳)1(i(𝐈𝐯^i𝐯^i𝖳)𝐩i).

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 Template:Math and a unit direction vector Template:Math. The square of the distance from a point Template:Math to one of the lines is given from Pythagoras:

di2=𝐩𝐚i2((𝐩𝐚i)𝖳𝐧^i)2=(𝐩𝐚i)𝖳(𝐩𝐚i)((𝐩𝐚i)𝖳𝐧^i)2

where Template:Math is the projection of Template:Math on line Template:Mvar. The sum of distances to the square to all lines is

idi2=i((𝐩𝐚i)𝖳(𝐩𝐚i)((𝐩𝐚i)𝖳𝐧^i)2)

To minimize this expression, we differentiate it with respect to Template:Math.

i(2(𝐩𝐚i)2((𝐩𝐚i)𝖳𝐧^i)𝐧^i)=0
i(𝐩𝐚i)=i(𝐧^i𝐧^i𝖳)(𝐩𝐚i)

which results in

(i(𝐈𝐧^i𝐧^i𝖳))𝐩=i(𝐈𝐧^i𝐧^i𝖳)𝐚i

where Template:Math is the identity matrix. This is a matrix Template:Math, with solution Template:Math, where Template:Math is the pseudo-inverse of Template:Math.

Non-Euclidean geometry

Template:See alsoTemplate:Expand section

From left to right: Euclidean geometry, spherical geometry, and hyperbolic geometry
From left to right: Euclidean geometry, spherical geometry, and hyperbolic geometry

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

References