janmr blog

Line-line Intersection in the Plane

How do you calculate the point where two lines in the plane intersect? It is not very hard to do, but the formula can look quite complicated, depending on how you write it up. This article is a reminder that it can be expressed in a simple manner.

We start out by not restricting ourselves to the plane, but any vector space with an inner product ,\langle \cdot, \cdot \rangle. Let two lines be represented as


p+sv,sR\text{p} + s \text{v}, \quad s \in \mathbb{R}


q+tw,tR\text{q} + t \text{w}, \quad t \in \mathbb{R}

where p\text{p}, q\text{q}, v\text{v}, and w\text{w} are vectors. We assume that both v\text{v} and w\text{w} are non-null. See Figure 1.

Line-line intersection
Figure 1. Line-line intersection

We look for values of ss and tt such that


p+sv=q+tw.\text{p} + s \text{v} = \text{q} + t \text{w}.

Let w^0\hat{\text{w}} \neq 0 be a vector perpendicular to w\text{w}, w,w^=0\langle \text{w}, \hat{\text{w}} \rangle = 0. We get


sv,w^=qp,w^s \langle \text{v}, \hat{\text{w}} \rangle = \langle \text{q} - \text{p}, \hat{\text{w}} \rangle

Now if v,w^=0\langle \text{v}, \hat{\text{w}} \rangle = 0 there are two possibilities: If qp,w^=0\langle \text{q} - \text{p}, \hat{\text{w}} \rangle = 0 there are infinitely many solutions, i.e., the lines overlap, but if qp,w^0\langle \text{q} - \text{p}, \hat{\text{w}} \rangle \neq 0 there are no solutions, i.e., the lines are parallel and do not intersect.

Assume then v,w^0\langle \text{v}, \hat{\text{w}} \rangle \neq 0. We get

s=qp,w^v,w^,s = \frac{\langle \text{q} - \text{p}, \hat{\text{w}} \rangle}{\langle \text{v}, \hat{\text{w}} \rangle},

and thus, after inserting into (1), the point of intersection is

p+qp,w^v,w^v.\text{p} + \frac{\langle \text{q} - \text{p}, \hat{\text{w}} \rangle}{\langle \text{v}, \hat{\text{w}} \rangle} \text{v}.

The Plane is Special

The derivation above is actually a little careless. If (2) is to hold for some ss and tt, then (3) must also hold. Turning the implication the other way, which we would like to, is less straightforward.

Assume that (3) holds for some value of ss,


sv+pq,w^=0.\langle s \text{v} + \text{p} - \text{q}, \hat{\text{w}} \rangle = 0.

What does this mean? It means that the vectors sv+pqs \text{v} + \text{p} - \text{q} and w^\hat{\text{w}} are perpendicular to each other, and if we are in two dimensions/the plane we must have sv+pq=tws \text{v} + \text{p} - \text{q} = t \text{w} for some value of tt. This is (2) and we are done.

Does this work in higher dimensions? Generally, no. Consider, e.g., three dimensions and Equation (4). What can we derive of it now? We have that

sv+pq=αw1+βw2s \text{v} + \text{p} - \text{q} = \alpha \text{w}_1 + \beta \text{w}_2

for some values of α\alpha and β\beta and where w1,w^=w2,w^=0\langle \text{w}_1, \hat{\text{w}} \rangle = \langle \text{w}_2, \hat{\text{w}} \rangle = 0. And αw1+βw2=tw\alpha \text{w}_1 + \beta \text{w}_2 = t \text{w} does not necessarily hold for any tt, so (2) does generally not follow in three dimensions or more.

Summary Using Coordinates

Let us consider the usual two-dimensional Euclidean space and Cartesian coordinates. We set

p=(p1,p2),q=(q1,q2),v=(v1,v2),w=(w1,w2),\text{p} = (p_1,p_2), \quad \text{q} = (q_1,q_2), \quad \text{v} = (v_1,v_2), \quad \text{w} = (w_1,w_2),

and use the inner product

(a1,a2),(b1,b2)=a1b1+a2b2.\langle (a_1,a_2), (b_1,b_2) \rangle = a_1 b_1 + a_2 b_2.

Rotating a vector w=(w1,w2)\text{w} = (w_1,w_2) counterclockwise by a right angle is easily done with w^=(w2,w1)\hat{\text{w}} = (-w_2, w_1). It is easily checked that w,w^=0\langle \text{w}, \hat{\text{w}} \rangle = 0.

Recall that we are interested in knowing whether the two lines

(x,y)=(p1,p2)+s(v1,v2),sR(x,y) = (p_1,p_2) + s (v_1,v_2), \quad s \in \mathbb{R}


(x,y)=(q1,q2)+t(w1,w2),tR(x,y) = (q_1,q_2) + t (w_1,w_2), \quad t \in \mathbb{R}


Setting α=w1v2w2v1\alpha = w_1 v_2 - w_2 v_1 and β=w1(q2p2)w2(q1p1)\beta = w_1 (q_2-p_2) - w_2 (q_1-p_1), we have

  • α=0\alpha = 0, β=0\beta = 0: The two lines overlap.
  • α=0\alpha = 0, β0\beta \neq 0: The lines are parallel but do not intersect.
  • α0\alpha \neq 0: The lines meet at a single point, (p1+βαv1,p2+βαv2)(p_1 + \frac{\beta}{\alpha} v_1, p_2 + \frac{\beta}{\alpha} v_2).