TExcelTAD
Home › Calculus in Depth › Coordinate Geometry and Lines

Coordinate Geometry and Lines

This reference lesson collects the analytic geometry that calculus takes for granted: distance and midpoints, slopes, the equations of a line, parallel and perpendicular lines, circles, and where two lines meet. Tangent lines, linear approximations and Newton's method all reuse these formulas.

Points, distance and midpoint

distanced=(x2−x1)2+(y2−y1)2(Pythagoras)midpointM=(x1+x22,y1+y22)\begin{aligned} &\text{distance} & d &= \sqrt{(x_2 - x_1)^2 + (y_2 - y_1)^2} && \text{(Pythagoras)} \\ &\text{midpoint} & M &= \left(\frac{x_1 + x_2}{2}, \frac{y_1 + y_2}{2}\right) \end{aligned}

Slope and the equations of a line

The slope of the line through (x1,y1)(x_1, y_1) and (x2,y2)(x_2, y_2), x1≠x2x_1 \ne x_2, is m=y2−y1x2−x1m = \frac{y_2 - y_1}{x_2 - x_1}: the rise per unit run. A vertical line has no slope.

Form Equation Use it when you know
Point-slope y−y1=m(x−x1)y - y_1 = m(x - x_1) a point and the slope (tangent lines!)
Slope-intercept y=mx+by = mx + b slope and yy-intercept bb
General Ax+By+C=0Ax + By + C = 0 anything, including vertical lines (B=0B = 0)
Vertical x=ax = a
Horizontal y=by = b slope 0
Two-intercept xa+yb=1\frac{x}{a} + \frac{y}{b} = 1 the intercepts aa and bb (both ≠0\ne 0)
Relation Condition on slopes General-form test
Parallel m1=m2m_1 = m_2 A1B2−A2B1=0A_1B_2 - A_2B_1 = 0
Perpendicular m1⋅m2=−1m_1 \cdot m_2 = -1 A1A2+B1B2=0A_1A_2 + B_1B_2 = 0

The perpendicular rule follows from the dot product: the line Ax+By+C=0Ax + By + C = 0 has normal vector ⟨A,B⟩\langle A, B \rangle, and two lines are perpendicular exactly when their normals are. See The Dot Product.

Distance from a point to a line

distance from (x0,y0) to Ax+By+C=0  =  ∣Ax0+By0+C∣A2+B2\text{distance from } (x_0, y_0) \text{ to } Ax + By + C = 0 \;=\; \frac{\lvert Ax_0 + By_0 + C \rvert}{\sqrt{A^2 + B^2}}

The numerator Ax0+By0+CAx_0 + By_0 + C is a signed quantity: its sign says which side of the line the point is on. Dividing by the length of the normal turns it into a true distance.

Circles and conics

A circle with centre (h,k)(h, k) and radius rr is (x−h)2+(y−k)2=r2(x - h)^2 + (y - k)^2 = r^2. To read the centre from an expanded equation, complete the square:

x2+y2−6x+4y−3=0(x2−6x+9)+(y2+4y+4)=3+9+4(x−3)2+(y+2)2=16centre (3,−2), radius 4\begin{aligned} x^2 + y^2 - 6x + 4y - 3 &= 0 \\ (x^2 - 6x + 9) + (y^2 + 4y + 4) &= 3 + 9 + 4 \\ (x - 3)^2 + (y + 2)^2 &= 16 && \text{centre } (3, -2),\ \text{radius } 4 \end{aligned}

Parabolas y=ax2+bx+cy = ax^2 + bx + c, ellipses x2a2+y2b2=1\frac{x^2}{a^2} + \frac{y^2}{b^2} = 1 and hyperbolas x2a2−y2b2=1\frac{x^2}{a^2} - \frac{y^2}{b^2} = 1 are treated fully in Conic Sections; a gentler survey is Conic Sections in the essentials course.

python · try it yourself
import sympy as sp

x, y = sp.symbols('x y')
A, B = (1, 5), (7, -3)
m = sp.Rational(B[1] - A[1], B[0] - A[0])
line = sp.Eq(y - A[1], m * (x - A[0]))
print("slope:", m, "  line:", sp.expand(sp.solve(line, y)[0]))
print("distance:", sp.sqrt((B[0] - A[0])**2 + (B[1] - A[1])**2))
print("midpoint:", ((A[0] + B[0]) / 2, (A[1] + B[1]) / 2))
perp_slope = -1 / m
print("perpendicular bisector: y =", sp.expand(perp_slope * (x - 4) + 1))
slope: -4/3   line: 19/3 - 4*x/3
distance: 10
midpoint: (4.0, 1.0)
perpendicular bisector: y = 3*x/4 - 2

SymPy prints −4x3+193-\frac{4x}{3} + \frac{19}{3} with the constant first; it is the same line.

Where two lines meet

Two lines A1x+B1y=C1A_1x + B_1y = C_1 and A2x+B2y=C2A_2x + B_2y = C_2 form a 2×22 \times 2 linear system. By Cramer's rule, with D=A1B2−A2B1D = A_1B_2 - A_2B_1:

x=C1B2−C2B1D,y=A1C2−A2C1D(D=0 means parallel or identical)x = \frac{C_1B_2 - C_2B_1}{D}, \quad y = \frac{A_1C_2 - A_2C_1}{D} \qquad (D = 0 \text{ means parallel or identical})

In software

Geometry code (games, CAD, GIS, collision detection) uses these formulas constantly, usually in the parametric form P+t dP + t\,d instead of y=mx+by = mx + b, because vertical lines and segments are then no special case. The determinant DD is a 2D cross product; it tells you if two segments cross, and which way a polygon turns. Because DD can be tiny but nonzero for almost-parallel lines, robust code compares it with a tolerance, not with 0.

python · try it yourself
def segment_intersection(p, p2, q, q2, eps=1e-12):
    d = (p2[0] - p[0], p2[1] - p[1])
    e = (q2[0] - q[0], q2[1] - q[1])
    denom = d[0] * e[1] - d[1] * e[0]          # 2D cross product
    if abs(denom) < eps:
        return None                             # parallel
    w = (q[0] - p[0], q[1] - p[1])
    t = (w[0] * e[1] - w[1] * e[0]) / denom
    u = (w[0] * d[1] - w[1] * d[0]) / denom
    if 0 <= t <= 1 and 0 <= u <= 1:
        return (p[0] + t * d[0], p[1] + t * d[1])
    return None

print(segment_intersection((0, 0), (4, 4), (0, 4), (4, 0)))
print(segment_intersection((0, 0), (1, 1), (3, 0), (4, -2)))
print(segment_intersection((0, 0), (2, 1), (0, 1), (4, 3)))
(2.0, 2.0)
None
None

The second pair of segments would meet only if extended; the third pair is parallel.

Exercises

Exercise 1: Tangent line

The line y=3x−2y = 3x - 2 is tangent to a curve at x=2x = 2. Write it in point-slope form, and give the line perpendicular to it at the same point.

Answer

y−4=3(x−2)y - 4 = 3(x - 2); the perpendicular (normal) line is y−4=−13(x−2)y - 4 = -\frac{1}{3}(x - 2), i.e. y=−x3+143y = -\frac{x}{3} + \frac{14}{3}.

Solution

At x=2x = 2 the line passes through y=3⋅2−2=4y = 3 \cdot 2 - 2 = 4, so the point is (2,4)(2, 4) and the slope 3. A perpendicular slope satisfies 3⋅m=−13 \cdot m = -1, so m=−13m = -\frac{1}{3}: y=4−x−23=−x3+143y = 4 - \frac{x - 2}{3} = -\frac{x}{3} + \frac{14}{3}.

Exercise 2: Centre and radius

Find the centre and radius of x2+y2+8x−10y+32=0x^2 + y^2 + 8x - 10y + 32 = 0.

Answer

Centre (−4,5)(-4, 5), radius 3.

Solution
(x2+8x+16)+(y2−10y+25)=−32+16+25(x+4)2+(y−5)2=9\begin{aligned} (x^2 + 8x + 16) + (y^2 - 10y + 25) &= -32 + 16 + 25 \\ (x + 4)^2 + (y - 5)^2 &= 9 \end{aligned}

Exercise 3: Point to line

Find the distance from (5,1)(5, 1) to the line 3x−4y+6=03x - 4y + 6 = 0.

Answer

175=3.4\frac{17}{5} = 3.4.

Solution
∣3⋅5−4⋅1+6∣9+16=∣17∣5=3.4\frac{\lvert 3 \cdot 5 - 4 \cdot 1 + 6 \rvert}{\sqrt{9 + 16}} = \frac{\lvert 17 \rvert}{5} = 3.4

Exercise 4: Intersection (code)

Solve 2x+3y=122x + 3y = 12 and x−y=1x - y = 1 with Cramer's rule in Python, using fractions.Fraction so the answer is exact.

Answer

x=3x = 3, y=2y = 2.

Solution

D=2⋅(−1)−1⋅3=−5D = 2 \cdot (-1) - 1 \cdot 3 = -5, x=12⋅(−1)−1⋅3−5=3x = \frac{12 \cdot (-1) - 1 \cdot 3}{-5} = 3, y=2⋅1−1⋅12−5=2y = \frac{2 \cdot 1 - 1 \cdot 12}{-5} = 2.

python · try it yourself
from fractions import Fraction as F

A1, B1, C1 = F(2), F(3), F(12)
A2, B2, C2 = F(1), F(-1), F(1)
D = A1 * B2 - A2 * B1
print(D, (C1 * B2 - C2 * B1) / D, (A1 * C2 - A2 * C1) / D)
-5 3 2

Test yourself

A line has slope 25\frac{2}{5}. What is the slope of a line perpendicular to it?

  1. −52-\frac{5}{2}
  2. 52\frac{5}{2}
  3. −25-\frac{2}{5}
  4. 25\frac{2}{5}

Which form can describe a vertical line?

  1. y=mx+by = mx + b
  2. Point-slope with slope mm
  3. Ax+By+C=0Ax + By + C = 0 with B=0B = 0
  4. None of them

In segment-intersection code, the 2D cross product of the two direction vectors is 0. What does it mean?

  1. The segments cross at their midpoints
  2. The segments are parallel (or collinear)
  3. The segments are perpendicular
  4. One segment has length 0, always