[Contents]

The Intersection of Two Lines
each represented by an anchor and a direction

John Denker

## 1  Preview

We shall see that it is sometimes advantageous to represent a line in the plane using four numbers, namely two vectors (with two components apiece), namely a position vector and a direction vector.

As a bonus, this approach allows us to represent not just the line as a whole, but also a special “anchor point” on the line. This is sometimes useful, e.g. to represent the “current” point or the “starting” point or some such.

For example, the point where two lines intersect is given by:

X = intersection point
=
A +
 (B−A)·pB pB·dA
dA
(1a)
=
B +
 (A−B)·pA pA·dB
dB
(1b)

The two expressions (equation 1a and equation 1b) are equivalent; you don’t need to evaluate both. The notation is explained in section 4.

Finding the intersection of two lines is a topic for high-school algebra, except that they do it without using vectors. In contrast, the last 999 times I wanted to find an intersection, the problem was already formulated in terms of vectors, and equation 1 was by far the most convenient way to proceed.

For example, suppose point A is a navigation fix or beacon, dA is a particular radial passing through that fix, B is your current position, and dB is your current velocity vector (aka heading). An autopilot or flight simulator might need to calculate the point of intersection, to predict where your path crosses the radial. (The actual calculation is more complicated than that, but even so, calculating intersections is one of the crucial ingredients.)

A spreadsheet that implements this calculation is given in reference 1. Figure 1: Points of Intersection

## 2  Background

By way of context and background, here are some other representations that are sometimes encountered:

• A point in the plane:
• This can be represented using two numbers, namely a vector with two components.
• A line in the plane:
• This can be represented imperfectly by two numbers, namely the x-intercept and the y-intercept. This representation becomes perfect if we allow the x-intercept to be infinite (for a horizontal line) or the y-intercept to be infinite (for a vertical line).
• This can also be represented imperfectly by two numbers: a y-intercept and a heading. This fails for a vertical line, because the y-intercept is infinite.

Similarly, you can use the x-intercept and the inverse slope. This fails for horizontal lines.

• You can replace the heading with the slope, i.e. the cotangent of the heading. This fails for vertical lines. (For vertical or near-vertical lines, you could perhaps use the inverse slope, but this fails for horizontal lines.)
• A line in the plane with an anchor point:
• This can be represented using three numbers, namely a vector to specify the point, and a heading to specify the direction.
• Again, you can replace the heading with a slope (or inverse slope). This fails for vertical (or horizontal) lines.
• This can be represented by four numbers, namely two (non-identical) position vectors. You can arbitrarily designate one of them (or the midpoint) as the “anchor” point.
• We shall focus on a representation that uses four numbers, namely a position vector and a direction vector, as discussed in section 3.

## 3  Discussion

Even though it “should” take only three numbers to represent a line with an anchor point, it is sometimes convenient to use four numbers, namely two vectors with two components apiece, namely a position vector (to specify the anchor point) and a direction vector (to specify the rest of the line).

 position vector = A = [Ax, Ay] (components)
(2)

 direction vector = dA = [dAx, dAy] = |v| [sin(θ), cos(θ)]
(3)

where θ is the heading, measured clockwise from north. Note: Mathematicians measure directions counterclockwise from east. In contrast, navigators measure headings clockwise from north, which is the convention used in equation 3.

Conceptually, we still require only three numbers, because we can impose a constraint. Without loss of generality, we can require the direction vector to be a unit vector, by setting |v|=1 in the last line of of equation 3.

On the other hand, sometimes it is advantageous to think in terms of a velocity vector (rather than a direction vector), in which case we really do need four numbers (two vectors) to specify what’s going on. Things get weird if the velocity is zero, in which case the heading is undefined and we don’t have a line at all; instead we just have an isolated point.

## 4  Derivation: Intersection of Two Lines

Suppose we have two lines:

 A(α) = A + α dA B(β) = B + β dB
(4)

for all α and β. To find the intersection, we need to find values of α and β such that

 A + α dA = B + β dB
(5)

or equivalently

 A − B + α dA − β dB = 0
(6)

this is a vector equation, so it counts as two equations in two unknowns, so it is well-posed (provided the two lines are not parallel).

We can convert this into a pair of scalar equations as follows:

 (A−B)·pA + 000 − β dB·pA = 0 (A−B)·pB + α dA·pB − 000 = 0
(7)

where pA is a vector formed by rotating dA by 90 degrees. We then solve:

β =
 (A−B)·pA dB·pA

α =
 (B−A)·pB dA·pB
(8)

So the intersection occurs at:

X = intersection point
=
A +
 (B−A)·pB pB·dA
dA
(9a)
=
B +
 (A−B)·pA pA·dB
dB
(9b)

## 5  Ramifications

### 5.1  Check the Work

We can improve our understanding of this by performing some simple checks:

• Both formulas give the correct answer, trivially, when A=B. The intersection occurs at X=A=B.
• Equation 9a gives the correct answer when the separation vector (AB) between the two anchor points is parallel to line B. In that case, it’s not just parallel, it’s collinear. The intersection occurs at X=A.

Similar logic applies to Equation 9b.

• Bad things happen when the two lines are parallel. The denominator goes to zero in both expressions. If the two lines are colinear, there are infinitely many points of intersection; otherwise none.
• We assume dA≠0 and dB≠0. Otherwise the whole situation is impossible.
• The answer is insensitive to the magnitude dA. The directional vector could be replaced by a unit vector in the same direction. Ditto for dB.
• If you displace the anchor point A by an amount that is proportional to dB, the intersection point moves by exactly the same amount.
• If you displace the anchor point A by an amount that is proportional to dA, the line itself is unchanged and the intersection point is unchanged.
• If point B lies on line A, the intersection occurs at X=B, no matter what dB is. This means there is a whole family of lines, with different dB but all with the same A, B, and X. You can see this in equation 9b, where the (ABpA factor is zero, independent of all the other factors.

### 5.2  Projection-like Operator

The expression for XA is hauntingly similar (but not identical) to a projection operator acting on BA. Using Dirac bra-ket notation to distingish row vectors from column vectors, we have:

|XA =
 |dA⟩⟨pB| ⟨dA|pB⟩
|BA
(10a)
=
 |dA⟩⟨pB| Tr |dA⟩⟨pB|
|BA
(10b)

If nothing else, this makes it easy to remember the formula. The pattern is:

• In equation 10, the operator is the built-up fraction. The numerator is an outer product while the denominator is an inner product.
• The only direction vector not involved in a dot product is |dA⟩, which makes sense, because the whole expression must be a vector in the dA direction. That is, it must be of the form α dA, for some scalar α, as in equation 4.

(The other direction vector in the numerator, namely ⟨pB|, gets dotted into |BA⟩, so it does not contribute to the direction of the overall expression.)

• Since there’s a dA upstairs, there has to be a dA downstairs.
• The other direction vector has to involve B, and it has to be pB (not dB).
• Since there’s a pB upstairs, there has to be a pB downstairs.
• If the two lines are perpendicular (and not otherwise), then the operator is really and truly a projection operator, which makes sense in terms of the geometry of the situation.

There’s probably an elegant geometrical interpretation of this operator, i.e. some concept that captures the general notion of outer product divided by inner product, including projection operators as a special case.... However, I’m not grasping the general case at the moment.

1.
John Denker,