Intersection point of two lines
(2 dimensions)

Written by Paul Bourke
April 1989

Sample source code
C++ contribution by Damian Coventry.
LISP implementation by Paul Reiners.
C version for Rockbox firmware by Karl Kurbjun.


This note describes the technique and algorithm for determining the intersection point of two lines (or line segments) in 2 dimensions.

The equations of the lines are

Pa = P1 + ua ( P2 - P1 )

Pb = P3 + ub ( P4 - P3 )

Solving for the point where Pa = Pb gives the following two equations in two unknowns (ua and ub)

x1 + ua (x2 - x1) = x3 + ub (x4 - x3)

and
y1 + ua (y2 - y1) = y3 + ub (y4 - y3)

Solving gives the following expressions for ua and ub

Substituting either of these into the corresponding equation for the line gives the intersection point. For example the intersection point (x,y) is

x = x1 + ua (x2 - x1)

y = y1 + ua (y2 - y1)

Notes: