Sub topic 2
Writing the equation of a line
This chapter assumes you can compute slopes, solve two linear equations in two unknowns, and use the Pythagorean theorem. Coordinates are written as (x, y).
Forms of the line equation
The slope of a line through (x1, y1) and (x2, y2) is m = (y2 - y1) / (x2 - x1). Each form of the equation suits a different set of known facts:
| Form | Equation | Use when you know |
|---|---|---|
| Slope-intercept | y = mx + c | slope and y-intercept |
| Point-slope | y - y1 = m(x - x1) | slope and one point |
| Two-point | (y - y1)/(y2 - y1) = (x - x1)/(x2 - x1) | two points |
| Intercept | x/a + y/b = 1 | x-intercept a and y-intercept b |
| General | ax + by + c = 0 | any line, and the form used for distances |
Parallel and perpendicular lines
Parallel lines have equal slopes. Perpendicular lines have slopes whose product is -1, provided neither line is vertical. For example, the line through (2, 1) parallel to y = 3x + 5 has slope 3, so y - 1 = 3(x - 2), which simplifies to y = 3x - 5.
Where lines meet: intersection and concurrency
Solve the two equations together to find the intersection point. Three lines are concurrent when they share one point. For example, x + y = 5 and x - y = 1 meet at (3, 2). The line 2x + y = 8 also passes through (3, 2), so the three lines are concurrent.
flowchart TD
A[Two lines given] --> B{Equal slopes?}
B -->|Yes| C[Parallel or identical]
B -->|No| D[Solve the pair for the intersection]caption: Choosing between a parallel check and solving for the intersection. alt: A flowchart. Two given lines lead to a decision on whether their slopes are equal. Equal slopes mean the lines are parallel or identical. Unequal slopes mean the next step is to solve the pair for their intersection.
Distance from a point to a line
The distance from (x0, y0) to the line ax + by + c = 0 is |ax0 + by0 + c| / sqrt(a² + b²). The area of a polygon follows from the shoelace formula, which sums cross-products of consecutive vertices.
def point_line_distance(x0, y0, a, b, c):
# distance from (x0, y0) to the line ax + by + c = 0
return abs(a * x0 + b * y0 + c) / (a ** 2 + b ** 2) ** 0.5
def polygon_area(points):
# shoelace formula; points are listed in order around the polygon
total = 0
for i in range(len(points)):
x1, y1 = points[i]
x2, y2 = points[(i + 1) % len(points)]
total += x1 * y2 - x2 * y1
return abs(total) / 2
print(point_line_distance(1, 2, 3, 4, -10))
print(polygon_area([(0, 0), (4, 0), (0, 3)]))The first print gives 0.2. The second gives 6.0.
Areas of triangles and polygons from coordinates
The shoelace formula works for any polygon whose vertices are listed in order. A triangle with vertices that are collinear has area 0, so the formula also tests collinearity.
Exercise
Find the area of the triangle with vertices (1, 1), (5, 1) and (1, 4).
Show answer
The base from (1, 1) to (5, 1) has length 4, and the height to (1, 4) is 3, so the area is 6. The shoelace sum is (1·1 - 5·1) + (5·4 - 1·1) + (1·1 - 1·4) = -4 + 19 - 3 = 12, and half of 12 is 6.