Sub topic 5
Writing an Equation from Two Points
This chapter assumes you can plot points, compute slope as rise over run, work with fractions and negative numbers, and solve a linear equation for one variable. You should also know slope-intercept form, y = mx + b, and the point-slope form from the previous chapter.
Two different points determine exactly one straight line. Given those points, you can find the line's equation in three steps:
- Compute the slope from the two points.
- Plug the slope and either point into point-slope form.
- Rewrite the result in whichever form the problem asks for.
The idea: slope first, then point-slope
Point-slope form, y - y1 = m(x - x1), needs one point and a slope. Two points give you two points and no slope. Computing the slope closes that gap.
For points (x1, y1) and (x2, y2), the slope is:
m = (y2 - y1) / (x2 - x1)
Once you have m, either point can serve as (x1, y1). Both choices produce the same line, and the two equations look different only until you simplify them.
Worked example 1: positive slope
Find the equation of the line through (1, 3) and (4, 9).
Step 1: slope.
m = (9 - 3) / (4 - 1) = 6 / 3 = 2
Step 2: point-slope form. Use (1, 3):
y - 3 = 2(x - 1)
Step 3: convert.
- Slope-intercept: y - 3 = 2x - 2, so y = 2x + 1.
- Standard form: move the x term to the left. Subtract 2x from both sides of y = 2x + 1 to get -2x + y = 1. Multiply by -1 so that A is non-negative: 2x - y = -1.
Check. Substitute both original points into 2x - y = -1:
- (1, 3): 2(1) - 3 = -1. ✓
- (4, 9): 2(4) - 9 = -1. ✓
Choosing which point to use
You can use the second point instead. With (4, 9):
y - 9 = 2(x - 4)
This looks different from y - 3 = 2(x - 1). Expand it:
y - 9 = 2x - 8, so y = 2x + 1.
You get the same slope-intercept equation. Point-slope forms built from different points of the same line are all equivalent. If your answer key shows a different point-slope equation than yours, expand both before deciding that one is wrong.
Worked example 2: negative slope and a fraction
Find the line through (-2, 5) and (4, 1).
Slope.
m = (1 - 5) / (4 - (-2)) = -4 / 6 = -2/3
Reduce the fraction before going further. Smaller numbers lower the chance of an error later.
Point-slope form using (4, 1):
y - 1 = -2/3 (x - 4)
Slope-intercept form. Distribute and add 1:
y - 1 = -2/3 x + 8/3
y = -2/3 x + 8/3 + 3/3
y = -2/3 x + 11/3
Standard form. Start from y - 1 = -2/3 (x - 4). Multiply both sides by 3 to clear the fraction:
3(y - 1) = -2(x - 4)
3y - 3 = -2x + 8
2x + 3y = 11
Here A = 2, B = 3, C = 11. All are integers with no common factor, and A is positive.
Check.
- (-2, 5): 2(-2) + 3(5) = -4 + 15 = 11. ✓
- (4, 1): 2(4) + 3(1) = 8 + 3 = 11. ✓
Order matters in the slope formula, but only for consistency
The slope formula works in either direction as long as you subtract in the same order in the numerator and the denominator:
- (y2 - y1) / (x2 - x1)
- (y1 - y2) / (x1 - x2)
Both give the same value. Mixing the orders flips the sign. For example, (9 - 3) / (1 - 4) = -2, which is wrong for the line in example 1.
Special cases
Vertical lines
If x1 = x2, the denominator of the slope is zero. A vertical line has no slope, so it has no point-slope form and no slope-intercept form. Its equation is x = x1.
For (3, 2) and (3, 7), the line is x = 3. In standard form that is 1x + 0y = 3.
Horizontal lines
If y1 = y2, the numerator is zero and the slope is 0. For (-1, 4) and (6, 4):
y - 4 = 0(x - (-1)), which simplifies to y = 4.
In standard form that is 0x + 1y = 4.
Identical points
If both points are the same, they do not determine a single line. Infinitely many lines pass through one point. The slope calculation gives 0/0, which is undefined. A problem that gives you the same point twice is missing information.
Doing it in code
The first function computes the slope from two points. It raises an error for a vertical line, because there is no slope to return. It then verifies the standard form by substituting both original points.
from fractions import Fraction
def slope_through(p, q):
(x1, y1), (x2, y2) = p, q
if x1 == x2:
raise ValueError(f"vertical line: x = {x1}")
return Fraction(y2 - y1, x2 - x1)
p, q = (1, 3), (4, 9)
m = slope_through(p, q) # 6/3 = 2
print(m) # 2
# Point-slope form using p: y - 3 = 2(x - 1)
# Check the standard form 2x - y = -1 by substituting both points.
A, B, C = 2, -1, -1
for x, y in (p, q):
assert A * x + B * y == CUsing Fraction instead of floating-point division keeps the slope exact. With floats, a slope of 2/3 becomes 0.6666..., and the equality check in the last step could fail because of rounding.
The next function converts point-slope form to standard form with integer coefficients. It clears the fractions, divides out the greatest common factor, and flips signs so A is non-negative.
from fractions import Fraction
from math import gcd
def point_slope_to_standard(m, x1, y1):
"""Convert y - y1 = m(x - x1) to Ax + By = C with integer A, B, C and A >= 0."""
m, x1, y1 = Fraction(m), Fraction(x1), Fraction(y1)
# y - y1 = m(x - x1) -> -m*x + y = y1 - m*x1
a, b, c = -m, Fraction(1), y1 - m * x1
# Clear denominators, then divide out the common factor.
den = a.denominator * c.denominator
a, b, c = int(a * den), int(b * den), int(c * den)
g = gcd(gcd(a, b), c)
a, b, c = a // g, b // g, c // g
if a < 0 or (a == 0 and b < 0):
a, b, c = -a, -b, -c
return a, b, c
print(point_slope_to_standard(2, 1, 3)) # (2, -1, -1) -> 2x - y = -1
print(point_slope_to_standard(Fraction(1, 2), 4, 1)) # (1, -2, 2) -> x - 2y = 2The first output matches example 1. You can confirm example 2 by calling point_slope_to_standard(Fraction(-2, 3), 4, 1), which returns (2, 3, 11).
A reference table
| Situation | Slope | Equation |
|---|---|---|
| x1 ≠ x2, y1 ≠ y2 | (y2 - y1) / (x2 - x1) | y - y1 = m(x - x1) |
| y1 = y2 | 0 | y = y1 |
| x1 = x2 | undefined | x = x1 |
| Same point twice | 0/0, undefined | Not determined |
Common errors
- Reversed subtraction. Subtracting y values in one order and x values in the other flips the sign of m.
- Dropping a negative sign in the point. With the point (-2, 5), the form is y - 5 = m(x - (-2)), which is y - 5 = m(x + 2). Writing x - 2 is wrong.
- Not distributing to every term. In 3(y - 1) = -2(x - 4), the 3 multiplies both y and -1.
- Leaving a fraction in standard form. Standard form here requires integer coefficients. Multiply through by the common denominator.
- Skipping the check. Substituting both points takes under a minute and catches nearly all of the errors above.
Exercises
Exercise
Write the equation of the line through (2, -1) and (6, 7) in slope-intercept form and in standard form with integer coefficients and A non-negative.
Show answer
Slope: m = (7 - (-1)) / (6 - 2) = 8/4 = 2. Using (2, -1): y + 1 = 2(x - 2), so y = 2x - 5. Standard form: -2x + y = -5, which becomes 2x - y = 5. Check (6, 7): 12 - 7 = 5. ✓
Exercise
Find the standard form of the line through (-3, 2) and (1, -4).
Show answer
Slope: m = (-4 - 2) / (1 - (-3)) = -6/4 = -3/2. Using (1, -4): y + 4 = -3/2 (x - 1). Multiply by 2: 2y + 8 = -3x + 3, so 3x + 2y = -5. Check (-3, 2): -9 + 4 = -5. ✓ Check (1, -4): 3 - 8 = -5. ✓
Exercise
A student finds the line through (2, 5) and (5, 11) and writes y - 5 = 2(x - 2). Another student writes y - 11 = 2(x - 5). Are both correct? Explain.
Show answer
Both are correct. The slope is (11 - 5)/(5 - 2) = 2. Each equation uses a different point on the same line. Expanding either gives y = 2x + 1.
Exercise
What is the equation of the line through (4, -3) and (4, 8), and why can't you write it in point-slope form?
Show answer
The x-coordinates are equal, so the slope formula has a zero denominator and the slope is undefined. The line is vertical, with equation x = 4. Point-slope form needs a slope, so it cannot describe this line.