Equations of line

Slope-intercept form

There are several ways to get an equation for a line. The most common is probably slope-intercept form:

$\qquad y = mx + b$

where $m$ is the gradient of the line and $b$ is where the line intersects the $y$-axis.

One problem with slope intercept form is that it doesn't work for vertical lines: a vertical line has an undefined gradient and doesn't intercept the $y$-axis. It's also a bit tricky to define a line segment. So we need another type of equation to represent the lines.

Parameterised lines

A useful way to define a line segment is to parameterise a line, which means introduce a parameter, normally $t$, which defines how far along the line you are. For example, we can define an equation:

$\qquad P = (1 - t)A + tB$

For every value of $t$ you'll get a point along the line $AB$. For example,

When $t=0$, $P=A$

When $t=1$, $P=B$

When $t=0.5$, $P$ is halfway between $A$ and $B$

This is useful for line segments since we can say we're only interested in points where $0 \geq t \geq 1$. We can also rearrange the equation to:

$\qquad P = A + (B - A)t$

This is perhaps clearer to understand. It says that we start at point $A$ and move along a vector that starts at $A$ and points to $B$, using $t$ as the proportion of the vector.

Solving simultaneous equations

Now we have a good way to represent lines, let's calculate where they cross (if they do). Start with four points, $A$, $B$, $C$ and $D$, where $A$ has coordinates $(A_x, A_y)$, $B$ has coordinates $(B_x, B_y)$, and so on. We want to find whether line segment $\overline{AB}$ intersects with line segment $\overline{CD}$.

It might be tempting to divide each side of the first equation by $(B_x - A_x)$ and each side of the second equation by $(B_y - A_y)$, to get them both in terms of $t$. However, then we would be left with the same problem that slope-intersection form gives, namely the equation is undefined when $\overline{AB}$ is vertical (since we would be dividing by $B_x - A_x$, which would be $0$).

So instead, we multiply the first equation by $(B_y - A_y)$, and the second equation by $(B_x - A_x)$:

Now we have an equation to find the value for $s$, how far along $\overline{CD}$ an intersection is.

Cross product

Our equation has similar terms in the numerator and denominator. In both cases it is the $x$ term from one vector multiplied by the $y$ term from another, and subtracted from the $y$ term from the first vector multiplied by the the $x$ term from the second. This operator is the the 2D cross product of the two vectors.

Notice too that the denominator of our equation is $dy_1 \cdot dx_2 - dx_1 \cdot dy_2$. We have gone to quite a lot of effort to avoid having zero in the denominator - will this expression ever equal zero, and if so when?

So our $s$ term will be undefined when gradient of $\overline{AB}$ equals the gradient of $\overline{CD}$. That makes sense because when the gradients are equal, the lines are either parallel or aligned. Either way, there is no meaningful intersection point.

Now we have calculated $s$, we first check whether $0 \geq s \geq 1$. If not, then the "intersection" occurs on a point not on $\overline{CD}$ (but it is on the line that passes through points $C$ and $D$). Then we can plug $s$ into either of the following equations to find $t$:

The final answer

Note that if $\overline{AB}$ is vertical, then $(B_x - A_x) = 0$, so in the first equation, the $t$ term disappears; in that case, use the second equation. Likewise, if the line in horizontal, you will have to use the first equation.

Once you have $t$, you check whether $0 \geq t \geq 1$, and if it is, then you do have an intersection. Finally, you can plug either $s$ or $t$ into one of the parameterised line equations to find the coordinates of the intersection point.

Leave a comment

Name*

Comment*

If you enter anything in this field your comment will be treated as spam