Lably
Skip to content

Line–line intersection

Common point(s) shared by two lines in Euclidean geometry

  • 9 min read
  • 4 chapters
Line-Line Intersection
Chase-san · Public domain

Learn it on Lably

In a Euclidean space, if two lines are not coplanar, they have no point of intersection and are called skew lines. If they are coplanar, however, there are three possibilities: if they coincide (are the same line), they have all of their infinitely many points in common; if they are distinct but have the same direction, they are said to be parallel and have no points in common; otherwise, they have a single point of intersection, denoted as singleton set, for instance {A}.

Non-Euclidean geometry describes spaces in which one line may not be parallel to any other lines, such as a sphere, and spaces where multiple lines through a single point may all be parallel to another line. In spherical and elliptic geometries, every pair of lines intersects, while in hyperbolic geometry there exist infinitely many distinct lines through a given point that do not intersect a given line. Projective geometry provides a unifying framework in which these different behaviors can be described by extending the notion of intersection to include ideal points, so that any two distinct lines intersect in exactly one point.

Formulas

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

First we consider the intersection of two lines L1 and L2 in two-dimensional space, with line L1 being defined by two distinct points (x1, y1) and (x2, y2), and line L2 being defined by two distinct points (x3, y3) and (x4, y4).

The intersection P of line L1 and L2 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=(x1y2−y1x2)(x3−x4)−(x1−x2)(x3y4−y3x4)(x1−x2)(y3−y4)−(y1−y2)(x3−x4)Py=(x1y2−y1x2)(y3−y4)−(y1−y2)(x3y4−y3x4)(x1−x2)(y3−y4)−(y1−y2)(x3−x4)

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

Given two points on each line segment

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 with respect to the line segments, we can define lines L1 and L2 in terms of first degree Bézier parameters:

L1=[x1y1]+t[x2−x1y2−y1],L2=[x3y3]+u[x4−x3y4−y3]

(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, where

t=|x1−x3x3−x4y1−y3y3−y4||x1−x2x3−x4y1−y2y3−y4|=(x1−x3)(y3−y4)−(y1−y3)(x3−x4)(x1−x2)(y3−y4)−(y1−y2)(x3−x4)

and

u=−|x1−x2x1−x3y1−y2y1−y3||x1−x2x3−x4y1−y2y3−y4|=−(x1−x2)(y1−y3)−(y1−y2)(x1−x3)(x1−x2)(y3−y4)−(y1−y2)(x3−x4),

with

(Px,Py)=(x1+t(x2−x1),y1+t(y2−y1))or(Px,Py)=(x3+u(x4−x3),y3+u(y4−y3))

There will be an intersection if 0 ≤ t ≤ 1 and 0 ≤ u ≤ 1. The intersection point falls within the first line segment if 0 ≤ t ≤ 1, and it falls within the second line segment if 0 ≤ u ≤ 1. 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.

In the case where the two line segments share an x axis and x2=x1+1, t and u simplify to t=u=y1−y3y1−y2−y3+y4, with (Px,Py)=(x1+t,y1+t(y2−y1))or(Px,Py)=(x1+t,y3+t(y4−y3)).

Given two line equations

The x and y 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 + c and y = bx + d where a and b are the slopes (gradients) of the lines and where c and d are the y-intercepts of the lines. At the point where the two lines intersect (if they do), both y 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 x,

ax−bx=d−c,

and so,

x=d−ca−b.

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:

y=ad−ca−b+c.

Hence, the point of intersection is

P=(d−ca−b,ad−ca−b+c).

Note that if a = b then the two lines are parallel and they do not intersect, unless c = d 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). The mapping from 3D to 2D coordinates is (x′, y′) = (⁠x/w⁠, ⁠y/w⁠). We can convert 2D points to homogeneous coordinates by defining them as (x, y, 1).

Assume that we want to find intersection of two infinite lines in 2-dimensional space, defined as a1x + b1y + c1 = 0 and a2x + b2y + c2 = 0. We can represent these two lines in line coordinates as U1 = (a1, b1, c1) and U2 = (a2, b2, c2). The intersection P′ of two lines is then simply given by

P′=(ap,bp,cp)=U1×U2=(b1c2−b2c1,a2c1−a1c2,a1b2−a2b1)

If cp = 0, the lines do not intersect.

Sign in to keep reading

3 more chapters are free with a Lably account.

More in Geometry