TExcelTAD
Home › Algebra › Equations of Lines

Equations of Lines

A straight line can be written in several equivalent forms, and each one is convenient for a different job: slope-intercept form for graphing, point-slope form for building a line from what you know, and standard form for systems of equations. This lesson covers all three, parallel and perpendicular lines, and linear interpolation, the line formula hiding inside every animation and slider.

The three forms

Form Equation You can read off Best for
slope-intercept y=mx+by = mx + b slope mm, yy-intercept (0,b)(0, b) graphing, computing yy from xx
point-slope y−y1=m(x−x1)y - y_1 = m(x - x_1) slope mm, one point (x1,y1)(x_1, y_1) writing a line from a point and a slope
standard Ax+By=CAx + By = C both intercepts quickly systems of equations, vertical lines

All three describe the same line; you move between them with ordinary algebra. Standard form is the only one that can write a vertical line (x=4x = 4 is 1⋅x+0⋅y=41 \cdot x + 0 \cdot y = 4).

Building a line

From a point and a slope. The line through (2,5)(2, 5) with slope 3:

point-slope:y−5=3(x−2)slope-intercept:y=3x−6+5=3x−1standard:3x−y=1\begin{aligned} \text{point-slope:} &\quad y - 5 = 3(x - 2) \\ \text{slope-intercept:} &\quad y = 3x - 6 + 5 = 3x - 1 \\ \text{standard:} &\quad 3x - y = 1 \end{aligned}

Point-slope form is just the slope formula rearranged: m=y−y1x−x1m = \frac{y - y_1}{x - x_1}, multiplied by (x−x1)(x - x_1).

From two points. Through (−1,4)(-1, 4) and (3,−4)(3, -4): first the slope, then point-slope with either point.

m=−4−43−(−1)=−84=−2y−4=−2(x+1)→y=−2x+2→2x+y=2check (3,−4):−2⋅3+2=−4 ✓\begin{aligned} &m = \frac{-4 - 4}{3 - (-1)} = \frac{-8}{4} = -2 \\ &y - 4 = -2(x + 1) \to y = -2x + 2 \to 2x + y = 2 \\ &\text{check } (3, -4)\text{:}\quad -2 \cdot 3 + 2 = -4\ \checkmark \end{aligned}
python · try it yourself
from fractions import Fraction as F

def line_forms(p, q):
    (x1, y1), (x2, y2) = p, q
    if x1 == x2:
        return f"vertical line x = {x1}"
    m = F(y2 - y1, x2 - x1)
    b = y1 - m * x1
    # standard form with whole numbers: multiply y = mx + b by m's denominator
    A, B, C = -m.numerator, m.denominator, b * m.denominator
    return f"y = {m}x + {b}   |   {A}x + {B}y = {C}"

print(line_forms((-1, 4), (3, -4)))
print(line_forms((0, 1), (4, 3)))
print(line_forms((5, 0), (5, 9)))
y = -2x + 2   |   2x + 1y = 2
y = 1/2x + 1   |   -1x + 2y = 2
vertical line x = 5

The second line, y=12x+1y = \frac{1}{2}x + 1, becomes −x+2y=2-x + 2y = 2 in standard form (multiply by 2). Many teachers prefer a positive AA, so x−2y=−2x - 2y = -2 is the same line written the conventional way.

Parallel and perpendicular lines

Relationship Slopes Example
parallel equal: m1=m2m_1 = m_2 y=2x+1y = 2x + 1 and y=2x−3y = 2x - 3
perpendicular negative reciprocals: m1⋅m2=−1m_1 \cdot m_2 = -1 y=2x+1y = 2x + 1 and y=−12x+5y = -\frac{1}{2}x + 5

Parallel lines rise at the same rate and never meet (that is the "no solution" system from Systems of Equations). For perpendicular lines, rotating a line by 90° turns a run-rise step (1,m)(1, m) into (−m,1)(-m, 1), whose slope is 1−m\frac{1}{-m}.

  • The line parallel to y=2x+1y = 2x + 1 through (1,−1)(1, -1): slope 2, so y+1=2(x−1)y + 1 = 2(x - 1), which is y=2x−3y = 2x - 3.
  • The line perpendicular to it through (4,3)(4, 3): slope −12-\frac{1}{2}, so y−3=−12(x−4)y - 3 = -\frac{1}{2}(x - 4), which is y=−12x+5y = -\frac{1}{2}x + 5.

Horizontal and vertical lines are perpendicular too, the one pair the product rule cannot express (0 times "undefined").

In software: linear interpolation (lerp)

Suppose you know two points of a line and want the value in between. The two-point line, written slightly differently, is linear interpolation:

y=y1+(y2−y1)⋅x−x1x2−x1y = y_1 + (y_2 - y_1) \cdot \frac{x - x_1}{x_2 - x_1}

The fraction t=x−x1x2−x1t = \frac{x - x_1}{x_2 - x_1} says how far xx is along the way from x1x_1 to x2x_2 (0 at the start, 1 at the end). With it the formula becomes the famous one-liner every game engine and UI framework ships:

lerp⁡(a,b,t)=a+(b−a)⋅tthe line through (0,a) and (1,b)inverse_lerp⁡(a,b,v)=v−ab−awhich t gives the value v?remap⁡(v,a,b,c,d)=lerp⁡(c,d,inverse_lerp⁡(a,b,v))\begin{aligned} \operatorname{lerp}(a, b, t) &= a + (b - a) \cdot t && \text{the line through } (0, a) \text{ and } (1, b) \\ \operatorname{inverse\_lerp}(a, b, v) &= \frac{v - a}{b - a} && \text{which } t \text{ gives the value } v\text{?} \\ \operatorname{remap}(v, a, b, c, d) &= \operatorname{lerp}(c, d, \operatorname{inverse\_lerp}(a, b, v)) \end{aligned}
python · try it yourself
def lerp(a, b, t):
    return a + (b - a) * t

def inverse_lerp(a, b, v):
    return (v - a) / (b - a)

def remap(v, a, b, c, d):
    return lerp(c, d, inverse_lerp(a, b, v))

# a keyframe animation: x = 100 px at 0 s, x = 400 px at 2 s
for t in [0.0, 0.5, 1.0, 2.0]:
    print(f"at {t} s: x = {remap(t, 0, 2, 100, 400)} px")

# a health bar: 0..250 HP drawn as 0..120 px
print("180 HP ->", round(remap(180, 0, 250, 0, 120), 2), "px")

# Celsius to Fahrenheit is the line through (0, 32) and (100, 212)
print("37 °C ->", round(remap(37, 0, 100, 32, 212), 1), "°F")
at 0.0 s: x = 100.0 px
at 0.5 s: x = 175.0 px
at 1.0 s: x = 250.0 px
at 2.0 s: x = 400.0 px
180 HP -> 86.4 px
37 °C -> 98.6 °F

Each remap call is the equation of the line through two known points, evaluated at a new xx. Animation systems interpolate between keyframes this way, colour pickers blend colours channel by channel, and chart code maps data values to pixels (the screen mapping in Coordinate Systems is a remap). For curved motion, tt is first bent by an easing function; see Lerp, Inverse Lerp and Remap and Easing Curves.

Note: Interpolation (xx between x1x_1 and x2x_2) is safe. Extrapolation (xx outside that range, t<0t < 0 or t>1t > 1) still follows the line but may leave the range you intended, such as a health bar wider than its frame. Clamp tt to [0,1][0, 1] when that matters.

Exercises

Exercise 1: Point and slope

Write the line with slope 4 through (1,−2)(1, -2) in all three forms.

Answer

y+2=4(x−1)y + 2 = 4(x - 1); y=4x−6y = 4x - 6; 4x−y=64x - y = 6.

Solution
point-slope:y−(−2)=4(x−1)→y+2=4x−4slope-intercept:y=4x−6standard:4x−y=6\begin{aligned} \text{point-slope:} &\quad y - (-2) = 4(x - 1) \to y + 2 = 4x - 4 \\ \text{slope-intercept:} &\quad y = 4x - 6 \\ \text{standard:} &\quad 4x - y = 6 \end{aligned}

Exercise 2: Two points

Find the equation of the line through (2,7)(2, 7) and (6,−1)(6, -1) in slope-intercept and standard form.

Answer

y=−2x+11y = -2x + 11; 2x+y=112x + y = 11.

Solution
m=−1−76−2=−84=−2y−7=−2(x−2)→y=−2x+11check (6,−1):−12+11=−1 ✓\begin{aligned} &m = \frac{-1 - 7}{6 - 2} = \frac{-8}{4} = -2 \\ &y - 7 = -2(x - 2) \to y = -2x + 11 \\ &\text{check } (6, -1)\text{:}\quad -12 + 11 = -1\ \checkmark \end{aligned}

Exercise 3: Read the slope

Rewrite 3x+4y=123x + 4y = 12 in slope-intercept form. What are the slope and the yy-intercept?

Answer

y=−34x+3y = -\frac{3}{4}x + 3: slope −34-\frac{3}{4}, yy-intercept (0,3)(0, 3).

Solution
4y=−3x+12y=−34x+3\begin{aligned} 4y &= -3x + 12 \\ y &= -\tfrac{3}{4}x + 3 \end{aligned}

Exercise 4: Perpendicular

Find the line perpendicular to 2x−5y=102x - 5y = 10 that passes through (2,−1)(2, -1).

Answer

y=−52x+4y = -\frac{5}{2}x + 4 (standard form 5x+2y=85x + 2y = 8).

Solution
given line:−5y=−2x+10→y=25x−2, slope 25perpendicular slope:−52y+1=−52(x−2)→y=−52x+5−1=−52x+4times 2:2y=−5x+8→5x+2y=8check (2,−1):10−2=8 ✓\begin{aligned} \text{given line:} &\quad -5y = -2x + 10 \to y = \tfrac{2}{5}x - 2,\ \text{slope } \tfrac{2}{5} \\ \text{perpendicular slope:} &\quad -\tfrac{5}{2} \\ &\quad y + 1 = -\tfrac{5}{2}(x - 2) \to y = -\tfrac{5}{2}x + 5 - 1 = -\tfrac{5}{2}x + 4 \\ \text{times 2:} &\quad 2y = -5x + 8 \to 5x + 2y = 8 \\ \text{check } (2, -1): &\quad 10 - 2 = 8\ \checkmark \end{aligned}
python · try it yourself
from fractions import Fraction as F
m1, m2 = F(2, 5), F(-5, 2)
print("product of slopes:", m1 * m2, " y at x=2:", m2 * 2 + 4)
product of slopes: -1  y at x=2: -1

Exercise 5: A volume slider

A volume slider goes from 0 to 100 and sets a gain from −60 dB to 0 dB along a straight line. What gain does slider position 75 give, and which slider position gives −42 dB? Use remap.

Answer

75 gives −15 dB; −42 dB is at position 30.

Solution
gain=−60+(0−(−60))⋅75100=−60+45=−15t=−42−(−60)60=1860=0.3→position 30\begin{aligned} \text{gain} &= -60 + (0 - (-60)) \cdot \tfrac{75}{100} = -60 + 45 = -15 \\ t &= \frac{-42 - (-60)}{60} = \frac{18}{60} = 0.3 \to \text{position } 30 \end{aligned}
python · try it yourself
def lerp(a, b, t): return a + (b - a) * t
def inverse_lerp(a, b, v): return (v - a) / (b - a)
def remap(v, a, b, c, d): return lerp(c, d, inverse_lerp(a, b, v))
print(remap(75, 0, 100, -60, 0), remap(-42, -60, 0, 0, 100))
-15.0 30.0

Test yourself

Which line is parallel to y=−3x+7y = -3x + 7?

  1. y=3x+7y = 3x + 7
  2. y=13x−2y = \frac{1}{3}x - 2
  3. y=−3x−1y = -3x - 1
  4. y=7x−3y = 7x - 3

What is the slope of a line perpendicular to y=23x+1y = \frac{2}{3}x + 1?

  1. 23\frac{2}{3}
  2. −23-\frac{2}{3}
  3. 32\frac{3}{2}
  4. −32-\frac{3}{2}

lerp(10, 30, 0.25) equals…

  1. 15
  2. 20
  3. 12.5
  4. 7.5