Sub topic 3
Writing a parallel or perpendicular line through a point
This chapter assumes you can compute slope from two points, rewrite a line as y = mx + b, and name right, supplementary, and congruent angles.
Writing a parallel or perpendicular line through a point
Parallel lines have equal slopes. Perpendicular lines have slopes that are negative reciprocals, so their product is -1. To write a line with slope m through a point (x0, y0), solve for the intercept: b = y0 - m·x0.
from fractions import Fraction
def parallel_through(m, point):
"""Return (slope, intercept) of the line with slope m through point."""
x0, y0 = point
return m, y0 - m * x0
def perpendicular_through(m, point):
"""Return (slope, intercept) of the line perpendicular to slope m through point."""
if m == 0:
raise ValueError("perpendicular to a horizontal line is vertical: x = x0")
m_perp = Fraction(-1) / Fraction(m)
x0, y0 = point
return m_perp, y0 - m_perp * x0
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 + 5Transversals and angle pairs
A transversal is a line that crosses two other lines. It forms eight angles, which fall into named pairs:
| Pair | Location | Relationship when the lines are parallel |
|---|---|---|
| Corresponding | Same position at each crossing | Congruent |
| Alternate interior | Between the lines, opposite sides of the transversal | Congruent |
| Alternate exterior | Outside the lines, opposite sides of the transversal | Congruent |
| Same-side interior | Between the lines, same side of the transversal | Supplementary |
Angle relationships when lines are parallel
Parallel lines cut by a transversal produce the congruent and supplementary pairs above. The rule also works in reverse. If one pair is congruent, the lines are parallel.
The perpendicular bisector of a segment
The perpendicular bisector of a segment passes through its midpoint at a right angle. For the segment from (0, 0) to (4, 2), the midpoint is (2, 1) and the segment slope is 1/2. The bisector slope is -2, so b = 1 - (-2)(2) = 5. The bisector is y = -2x + 5.
Distance from a point to a line
Write the line as Ax + By + C = 0. The distance from point (x0, y0) to the line is |Ax0 + By0 + C| / sqrt(A² + B²). Two parallel lines Ax + By + C1 = 0 and Ax + By + C2 = 0 are separated by |C1 - C2| / sqrt(A² + B²).
import math
def point_line_distance(A, B, C, point):
x0, y0 = point
return abs(A * x0 + B * y0 + C) / math.hypot(A, B)
def parallel_lines_distance(A, B, C1, C2):
return abs(C1 - C2) / math.hypot(A, B)
print(point_line_distance(3, 4, -10, (0, 0))) # 2.0
print(parallel_lines_distance(3, 4, -10, 5)) # 3.0> Note: the callout below uses the required fence syntax.
Exercise
Write the equation of the line through (1, 2) that is parallel to y = 3x + 2.
Show answer
y = 3x - 1, because the intercept is b = 2 - 3(1) = -1.