Sub topic 2
Parallel lines have equal slopes
This chapter assumes you can plot points on a coordinate plane, solve a linear equation in one variable, and compute slope as rise over run.
Parallel lines have equal slopes
Two lines in a plane are parallel when they never meet. Their slopes are equal. If line 1 has slope m1 and line 2 has slope m2, then m1 = m2 means the lines are parallel or identical.
The slope through points (x1, y1) and (x2, y2) is (y2 - y1) / (x2 - x1), provided x1 is not equal to x2.
from fractions import Fraction
def slope(p, q):
(x1, y1), (x2, y2) = p, q
if x1 == x2:
return None # vertical line, slope undefined
return Fraction(y2 - y1, x2 - x1)
m1 = slope((0, 1), (4, 9)) # slope 2
m2 = slope((0, 0), (1, 2)) # slope 2
print(m1, m2, m1 == m2) # 2 2 True, so the lines are parallelFraction keeps slopes exact, so equality tests do not suffer from rounding.
Perpendicular slopes are negative reciprocals
Two lines are perpendicular when they meet at a right angle. If one slope m1 is nonzero, a perpendicular line has slope -1/m1. Equivalently, m1 * m2 = -1.
For example, y = 2x + 1 has slope 2. Any line perpendicular to it has slope -1/2.
Vertical and horizontal lines
A horizontal line has slope 0. A vertical line has no defined slope, because x2 - x1 = 0. Every horizontal line is perpendicular to every vertical line.
Deciding the relationship
Exercises
Exercise
Are the lines y = 3x + 1 and y = -3x + 1 parallel, perpendicular, or neither?
Show answer
Their slopes are 3 and -3. The slopes are not equal, and their product is -9, not -1. The lines are neither parallel nor perpendicular.