Calculus meets geometry. A curve has curvature (how fast it turns). A surface has Gaussian curvature (how it bends in two directions at once). Geodesics are the straightest paths on curved surfaces. General relativity is differential geometry applied to spacetime.
Curves and curvature
A plane curve can be parameterized as (x(t), y(t)). Its curvature kappa measures how quickly the tangent direction changes. For a circle of radius R, kappa = 1/R everywhere. For a straight line, kappa = 0. The osculating circle at each point is the best-fitting circle, and its radius is 1/kappa.
Scheme
; Curvature of a parameterized curve; kappa = |x'y'' - y'x''| / (x'^2 + y'^2)^(3/2); For a circle of radius R: x(t) = R*cos(t), y(t) = R*sin(t); x' = -R*sin(t), y' = R*cos(t); x'' = -R*cos(t), y'' = -R*sin(t); kappa = |(-R*sin)(- R*sin) - (R*cos)(-R*cos)| / R^3; = |R^2 sin^2 + R^2 cos^2| / R^3; = R^2 / R^3 = 1/R
(define (curvature-circle r)
(/ 1 r))
(display "Curvature of circle R=5: ")
(display (curvature-circle 5))
(newline)
(display "Curvature of circle R=10: ")
(display (curvature-circle 10))
(newline)
; Bigger radius = smaller curvature = less bending
(display "Curvature of circle R=100: ")
(display (curvature-circle 100))
(newline)
; For a parabola y = x^2 at x=0:; Parameterize as (t, t^2): x'=1, y'=2t, x''=0, y''=2; kappa = |1*2 - 2t*0| / (1 + 4t^2)^(3/2); At t=0: kappa = 2
(display "Curvature of y=x^2 at origin: ")
(display 2)
(newline)
(display "Osculating circle radius at origin: ")
(display (/ 12))
Python
importmathdef curvature_at(xp, yp, xpp, ypp):
"""Curvature from first and second derivatives."""
num = abs(xp * ypp - yp * xpp)
den = (xp**2 + yp**2) ** 1.5return num / den
# Circle of radius 5: x'=-5sin, y'=5cos, x''=-5cos, y''=-5sin# At t=0: x'=0, y'=5, x''=-5, y''=0
k = curvature_at(0, 5, -5, 0)
print(f"Curvature of circle R=5: {k}")
print(f"Osculating radius: {1/k}")
# Parabola y=x^2 at origin: x'=1, y'=0, x''=0, y''=2
k2 = curvature_at(1, 0, 0, 2)
print(f"Curvature of y=x^2 at origin: {k2}")
print(f"Osculating radius: {1/k2}")
Gaussian curvature
At each point on a surface, slice it with planes through the normal. Each slice gives a curve with some curvature. The maximum and minimum curvatures are the principal curvatures k1 and k2. Their product K = k1 * k2 is the Gaussian curvature. K > 0 means the surface bends the same way in all directions (sphere). K < 0 means it bends opposite ways (saddle). K = 0 means it's flat or cylindrical.
Scheme
; Gaussian curvature K = k1 * k2; Sphere of radius R: k1 = k2 = 1/R
(define (gaussian-sphere r)
(/ 1 (* r r)))
(display "Gaussian curvature of sphere R=1: ")
(display (gaussian-sphere 1))
(newline)
(display "Gaussian curvature of sphere R=5: ")
(display (gaussian-sphere 5))
(newline)
; Cylinder: k1 = 1/R, k2 = 0 (flat along the axis)
(define (gaussian-cylinder r)
(* (/ 1 r) 0))
(display "Gaussian curvature of cylinder: ")
(display (gaussian-cylinder 5))
(newline)
; Saddle point: k1 = a, k2 = -a
(define (gaussian-saddle a)
(* a (- a)))
(display "Gaussian curvature of saddle (a=1): ")
(display (gaussian-saddle 1))
(newline)
; Plane: k1 = k2 = 0
(display "Gaussian curvature of plane: ")
(display 0)
Geodesics
A geodesic is the shortest path between two points on a surface. On a plane, geodesics are straight lines. On a sphere, geodesics are great circles. On a saddle, geodesics curve in surprising ways. In general relativity, objects in free fall follow geodesics through curved spacetime.
Scheme
; Geodesic on a sphere = great-circle arc; Already computed in Ch.5 with the haversine formula
(define pi 3.141592653589793)
(define (deg->rad d) (* d (/ pi 180)))
(define (great-circle-distance lat1 lon1 lat2 lon2 r)
(let ((dlat (deg->rad (- lat2 lat1)))
(dlon (deg->rad (- lon2 lon1)))
(rlat1 (deg->rad lat1))
(rlat2 (deg->rad lat2)))
(let ((a (+ (* (sin (/ dlat 2)) (sin (/ dlat 2)))
(* (cos rlat1) (cos rlat2)
(sin (/ dlon 2)) (sin (/ dlon 2))))))
(* r 2 (asin (sqrt a))))))
(display "NYC to London (geodesic, km): ")
(display (great-circle-distance 40.7-74.051.5-0.16371))
(newline)
; Straight-line (through the Earth) would be shorter; but not a valid path on the surface.; The geodesic IS the shortest surface path.; On a flat plane, geodesic = straight line = Euclidean distance
(define (flat-distance x1 y1 x2 y2)
(sqrt (+ (* (- x2 x1) (- x2 x1))
(* (- y2 y1) (- y2 y1)))))
(display "Flat geodesic (0,0) to (3,4): ")
(display (flat-distance 0034))
Theorema Egregium
Gauss proved that Gaussian curvature depends only on the metric (how you measure distances on the surface), not on how the surface sits in space. A cylinder has K = 0 because you can unroll it flat without stretching. A sphere has K > 0 and cannot be flattened, which is why every flat map of the Earth distorts something.
Scheme
; Theorema Egregium consequence:; You cannot flatten a sphere without distortion.; Map projections trade off different distortions.; Mercator projection: preserves angles, distorts area
(define (mercator lat lon)
(let ((x (deg->rad lon))
(y (log (/ (+ 1 (sin (deg->rad lat)))
(cos (deg->rad lat))))))
(list x y)))
(define pi 3.141592653589793)
(define (deg->rad d) (* d (/ pi 180)))
; Compare areas at different latitudes; Mercator scale factor at latitude phi = 1/cos(phi)
(define (mercator-scale lat)
(/ 1 (cos (deg->rad lat))))
(display "Mercator scale at equator: ")
(display (mercator-scale 0))
(newline)
(display "Mercator scale at 60N: ")
(display (mercator-scale 60))
(newline)
(display "Mercator scale at 80N: ")
(display (mercator-scale 80))
(newline)
; Greenland looks as big as Africa on Mercator,; but Africa is 14x larger.
(display "Scale ratio 80N/equator: ")
(display (mercator-scale 80))