Other ways to measure distance
Change how distance is measured and the plane is the same set of points with a different geometry. In a city of square blocks the distance that matters is , and circles turn into squares.
const taxi = metric("taxicab"); // also "chebyshev" (max(|dx|, |dy|)) and "euclidean"
taxi.distance([0, 0], [3, 4]); // 7
taxi.circle([0, 0], 2); // the corners (2,0), (0,2), (−2,0), (0,−2)
taxi.pi; // 4
taxi.bisector([0, 0], [4, 2]); // a bent line: { segments, rays, regions, kind }
taxi.ellipse([0, 0], [4, 0], 6); // six corners
Circles and π
A circle is the set of points at a fixed distance from a centre. In the taxicab metric is a square standing on a corner; in the Chebyshev metric is a square with level sides. Measuring the circumference in the same metric and dividing by the diameter gives 4 in both, so "π = 4" there. The two metrics are in fact the same geometry turned by 45° and rescaled, and ellipse for the Chebyshev metric is computed through that change of coordinates.
Bisectors
The points equally far from P and Q form a straight line in Euclid's geometry. In taxicab geometry the middle part is a segment of slope ±1, and it continues from each end as a vertical ray (when P and Q are further apart sideways than up and down) or a horizontal one. When something stranger happens: beyond each end of the diagonal segment an entire quarter of the plane is equidistant from the two points. bisector returns the segment, the rays and, in that case, the two regions by their corner and bounding directions.
One consequence: the theorem that three points not on a line have exactly one point equidistant from all of them fails. Three such points can have none, or infinitely many.
Ellipses
The points whose distances to two foci add up to a constant form a hexagon or an octagon. ellipse returns its corners, found exactly: the sum of distances is a convex function that is linear between the vertical and horizontal lines through the foci, so the corners lie on those lines.
Side-angle-side fails
Congruence fails too. The triangle (0,0), (2,0), (0,2) and the triangle (0,0), (1,1), (1,−1) each have two sides of taxicab length 2 from the origin with a right angle between them, yet the third sides have taxicab lengths 4 and 2. Side-angle-side is not a theorem here, and taxicab geometry is the standard example of a geometry that satisfies Euclid's other axioms without it.
| call | returns |
|---|---|
| metric(name).distance(p, q) | exact number |
| .circle(centre, r) | the four corners |
| .pi | circumference ÷ diameter in that metric |
| .bisector(p, q) (taxicab) | { segments, rays, regions, kind } |
| .ellipse(f1, f2, sum) | the corners, counter-clockwise |
@ratmath/geo and Core's Rational in scope. The last line's value is shown; PRINT(…) adds lines, TEX(…) typesets math.