Intersection point of two lines
Written by Paul Bourke |
Sample source code Original C code by Paul Bourke. C++ contribution by Damian Coventry. LISP implementation by Paul Reiners. C version for Rockbox firmware by Karl Kurbjun. C# version by Olaf Rabbachin. VB.net version by Olaf Rabbachin. |
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
Pb = P3 + ub ( P4 - P3 )
Solving for the point where Pa = Pb gives the following two equations in two unknowns (ua and ub)
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
y = y1 + ua (y2 - y1)