Sub topic 8
Writing a parallel or perpendicular line through a point
This chapter assumes you can compute a slope from two points, move between slope-intercept, point-slope, and standard form, solve a linear equation in one variable, and do fraction arithmetic. It also assumes you know the two slope tests from earlier chapters: parallel lines have equal slopes, and perpendicular slopes are negative reciprocals.
Here you turn those tests into a procedure. Given a line and a point, you will write the equation of the new line through that point that is parallel or perpendicular to the given line. You will also learn where the procedure breaks and how to check your answer.
The problem
You are given:
- a line, in any form, and
- a point $(x0, y0)$, which may or may not lie on that line.
You must produce a line that passes through $(x0, y0)$ and is either parallel or perpendicular to the given line. Exactly one such line exists in each case. The slope test fixes the direction of the new line, and the point fixes its position.
The procedure
- Find the slope $m$ of the given line. Rewrite the line in slope-intercept form if needed.
- Choose the new slope $m'$:
- parallel: $m' = m$
- perpendicular: $m' = -\dfrac{1}{m}$
- Substitute $m'$ and the point into point-slope form, $y - y0 = m'(x - x0)$.
- Simplify to the form the problem asks for.
Worked example 1: slope-intercept input
Given the line $y = 2x + 1$ and the point $(4, 3)$.
Parallel line. The slope stays $2$. Point-slope form gives
$$y - 3 = 2(x - 4)$$
so $y = 2x - 8 + 3 = 2x - 5$.
Perpendicular line. The slope is $-\tfrac{1}{2}$. Point-slope form gives
$$y - 3 = -\tfrac{1}{2}(x - 4)$$
so $y = -\tfrac{1}{2}x + 2 + 3 = -\tfrac{1}{2}x + 5$.
You can use the shortcut $b = y0 - m'x0$ instead of expanding point-slope form. For the parallel line, $b = 3 - 2 \cdot 4 = -5$. For the perpendicular line, $b = 3 - (-\tfrac{1}{2})(4) = 5$.
from fractions import Fraction
def parallel_through(m, point):
x0, y0 = point
b = y0 - m * x0
return m, b
def perpendicular_through(m, point):
if m == 0:
raise ValueError("perpendicular to a horizontal line is the vertical line x = point[0]")
x0, y0 = point
m_perp = -1 / Fraction(m)
b = y0 - m_perp * x0
return m_perp, b
# Given y = 2x + 1 and the point (4, 3)
print(parallel_through(2, (4, 3))) # (2, -5) -> y = 2x - 5
print(perpendicular_through(2, (4, 3))) # (Fraction(-1, 2), Fraction(5, 1)) -> y = -1/2 x + 5The code uses Fraction so that $-1/m$ stays exact. With floats, a slope such as $-1/3$ becomes $-0.3333\ldots$ and equality checks later can fail.
Worked example 2: standard-form input
Given $2x + 5y = 10$ and the point $(-3, 2)$, find the line perpendicular to it through the point.
- Solve for $y$: $5y = -2x + 10$, so $y = -\tfrac{2}{5}x + 2$. The slope is $-\tfrac{2}{5}$.
- The negative reciprocal is $\tfrac{5}{2}$.
- Point-slope form: $y - 2 = \tfrac{5}{2}(x + 3)$.
- Distribute: $y = \tfrac{5}{2}x + \tfrac{15}{2} + 2 = \tfrac{5}{2}x + \tfrac{19}{2}$.
Watch the sign in step 3. The point has $x0 = -3$, so $x - x0$ becomes $x + 3$.
A shortcut for standard form
If the given line is $Ax + By = C$, you can skip the slope entirely.
- A parallel line has the same left side: $Ax + By = k$. Find $k$ by substituting the point: $k = Ax0 + By0$.
- A perpendicular line swaps the coefficients and negates one: $Bx - Ay = k$. Again $k = Bx0 - Ay0$.
For the line $3x - 4y = 8$ and the point $(2, -1)$:
- Parallel: $k = 3(2) - 4(-1) = 10$, so $3x - 4y = 10$.
- Perpendicular: here $A = 3$ and $B = -4$, so the left side is $-4x - 3y$. Then $k = -4(2) - 3(-1) = -5$, so $-4x - 3y = -5$, which is the same line as $4x + 3y = 5$.
The shortcut works because the given line has slope $-A/B$, and $B x - A y = k$ has slope $B/A$. Those are negative reciprocals. It also handles vertical and horizontal lines without any special treatment, because it never divides.
Special cases
The slope formula $m' = -1/m$ fails when $m = 0$, and a vertical line has no slope at all. Handle these cases directly.
| Given line | Parallel through $(x_0, y_0)$ | Perpendicular through $(x_0, y_0)$ |
|---|---|---|
| Horizontal, $y = c$ (slope 0) | $y = y_0$ | $x = x_0$ |
| Vertical, $x = c$ (slope undefined) | $x = x_0$ | $y = y_0$ |
| Any other slope $m$ | slope $m$ | slope $-1/m$ |
A horizontal line is perpendicular to a vertical one even though the product-of-slopes test cannot be applied. The test only covers lines that both have slopes.
For example, take the line $y = 7$ and the point $(4, 3)$. The parallel line is $y = 3$. The perpendicular line is $x = 4$. Neither answer can be written as $y = mx + b$, and the second answer has no $y$ at all.
A complete function
This function combines all three cases. It represents a vertical line by a slope of None, the same convention as the slope function from the earlier chapter on slope.
from fractions import Fraction
def format_line(m, b):
if m == 0:
return f"y = {b}"
sign = "+" if b >= 0 else "-"
return f"y = {m}x {sign} {abs(b)}"
def through_point(m, point, relation):
# m is None for a vertical line.
x0, y0 = point
if relation == "parallel":
new_m = None if m is None else Fraction(m)
elif relation == "perpendicular":
if m is None:
new_m = Fraction(0)
elif m == 0:
new_m = None
else:
new_m = -1 / Fraction(m)
else:
raise ValueError("relation must be 'parallel' or 'perpendicular'")
if new_m is None:
return f"x = {x0}"
b = y0 - new_m * x0
return format_line(new_m, b)
print(through_point(2, (4, 3), "parallel")) # y = 2x - 5
print(through_point(2, (4, 3), "perpendicular")) # y = -1/2x + 5
print(through_point(0, (4, 3), "perpendicular")) # x = 4
print(through_point(None, (4, 3), "perpendicular")) # y = 3
print(through_point(None, (4, 3), "parallel")) # x = 4Checking your answer
Run these checks before you accept an answer.
- Point check. Substitute $(x0, y0)$ into your final equation. Both sides must match. In example 2, $y = \tfrac{5}{2}x + \tfrac{19}{2}$ at $x = -3$ gives $-\tfrac{15}{2} + \tfrac{19}{2} = 2$. ✓
- Slope check. For parallel, the slopes are equal. For perpendicular, their product is $-1$.
- Different line check. If the point already lies on the given line, the parallel answer is the given line itself. This is correct, since a line is parallel to itself under the "same slope" definition used here. It is not a mistake, but it is worth noticing.
Common errors
- Using the wrong point coordinates. Writing $y - 3 = 2(x - 4)$ as $y + 3 = 2(x + 4)$ shifts the line to a different point.
- Reading the slope from standard form. In $2x + 5y = 10$ the slope is not $2$ and not $\tfrac{2}{5}$. It is $-\tfrac{A}{B} = -\tfrac{2}{5}$.
- Reusing the intercept. The new line has a different $b$ in general. Copying $b$ from the given line is only correct when the point lies on the $y$-axis at that intercept.
- Dividing by zero. Always inspect the slope before computing $-1/m$.
- Leaving fractions in a half-simplified state. If the problem asks for standard form with integer coefficients, multiply through by the common denominator. For $y = \tfrac{5}{2}x + \tfrac{19}{2}$, multiply by $2$ to get $2y = 5x + 19$, then rearrange to $5x - 2y = -19$.
Exercises
Exercise
Write the equation, in slope-intercept form, of the line through (6, -2) that is parallel to 3x + 2y = 12.
Show answer
Solve for y: 2y = -3x + 12, so y = -3/2 x + 6. The slope is -3/2. The parallel line has the same slope. Compute b = y0 - m x0 = -2 - (-3/2)(6) = -2 + 9 = 7. The line is y = -3/2 x + 7. Check: at x = 6, y = -9 + 7 = -2. ✓
Exercise
Write the equation of the line through (-1, 5) that is perpendicular to y = -4x + 9.
Show answer
The given slope is -4. The negative reciprocal is 1/4. Compute b = 5 - (1/4)(-1) = 5 + 1/4 = 21/4. The line is y = 1/4 x + 21/4, or x - 4y = -21 in standard form. Check: the slopes multiply to -4 · 1/4 = -1, and at x = -1, y = -1/4 + 21/4 = 5. ✓
Exercise
Find the line through (5, 8) perpendicular to the vertical line x = -2, and the line through (5, 8) parallel to it.
Show answer
A vertical line has an undefined slope, so use the special cases. The perpendicular line is horizontal through the point: y = 8. The parallel line is vertical through the point: x = 5.