@ratmath/geo

Geometry where equal means equal

Three points are on a line or they are not, and a floating-point test can only say "nearly". Here coordinates are exact: fractions, or algebraic numbers such as 3/2\sqrt3/2 when a compass has been used. So collinear, concyclic and tangent are decided, and a theorem checked on a figure is checked.

What is here

A first program

import { triangle, circle, line, meet, rotation, theorems, delaunay, pick, metric } from "@ratmath/geo";

const t = triangle([0, 0], [4, 0], [1, 3]);
String(t.orthocenter);                      // "(1, 1)"
String(t.incenter);                         // exact, with nested square roots
theorems.feuerbach(t).holds;                // true: the nine-point circle touches the incircle
meet(circle([0, 0], [1, 0]), circle([1, 0], [0, 0])).map(String);   // ["(1/2, -√3/2)", "(1/2, √3/2)"]
String(rotation([0, 0], "1/6").apply([1, 0]));                      // "(1/2, √3/2)"
delaunay([[0, 0], [1, 0], [0, 1], [1, 1]]).cocircular;              // true: decided, not guessed
pick([[0, 0], [5, 0], [0, 5]]);             // { area: 25/2, interior: 6, boundary: 15, holds: true }
metric("taxicab").pi;                       // 4

Numbers

A coordinate is a Core Rational whenever it is rational, and otherwise an algebraic number from @ratmath/algebraic, which keeps its minimal polynomial and so can be added, compared and tested for zero exactly. Everything a ruler and compass can construct is such a number, and so are the vertices of every regular polygon. Inputs are whole numbers, fractions "7/2", decimals "0.35" (meaning 7/20) and square roots "sqrt(3)/2". A JavaScript number that is not whole is refused. N exports the arithmetic (N.add, N.sqrt, N.cmp, N.text…).

Rational figures stay rational and fast. Figures with square roots are slower, since each comparison works with minimal polynomials; a triangle's incentre and the circles around it take a fraction of a second.

Projective, finite, solid and symmetric

The projective plane works in homogeneous coordinates, where cross-ratios and projective maps are exact and Desargues, Pappus, Pascal and Brianchon can be checked on any exact figure. Finite geometries are built over algebraic's finite fields, from the seven-point Fano plane up, with their collineation groups. Polyhedra have exact coordinates in Q(√2) or Q(√5): volumes, dihedral angles, duals and symmetry groups. Plane patterns get their rosette, frieze or wallpaper group, and the tilings page shows why only 11 of the 21 vertex types of regular polygons tile uniformly. Pictures of geometry grows and draws those 11 tilings, draws solids, patterns, finite planes and constructions with RatMath Graphics, and joins geo's exact plane with graphics'.

The sphere and the hyperbolic plane

On the sphere a triangle's angles add up to more than π, and in the hyperbolic plane to less; in both, the difference is the area. Points have exact coordinates, distances keep their exact cosine or cosh, and whether an angle is a rational multiple of π is decided, so the octant triangle covers exactly one eighth of the sphere and a triangle with three ideal vertices has area exactly π. The hyperbolic plane is one object seen in four models, with its isometries classified and its regular tilings sized exactly. The parallel postulate is then a count that comes out differently in each geometry.

Proofs for every figure

A check tests one figure. General proofs cover all of them: the coordinates are letters, the hypotheses and conclusion are polynomials, and the proof is one polynomial identity found by Wu's method or a Gröbner basis and then multiplied out to confirm. The Euler line, the nine-point circle, Simson's line, the butterfly theorem, Pappus and Desargues are among the twenty-one proved, each with its degenerate cases listed.

import { proofs, configuration } from "@ratmath/geo";

const p = proofs.eulerLine();
p.proved;                                  // true, for every triangle
p.conditions.map((c) => c.meaning);       // ["A, B, C are not collinear"]
p.replay();                                // true: the certificate multiplies out

Every phase of the roadmap for this package is now built. The RatMath Shelf page lists what exists across all the libraries.

Try itEdit the code and run it with @ratmath/geo and Core's Rational in scope. The last line's value is shown; PRINT(…) adds lines, TEX(…) typesets math.
Ctrl/⌘ + Enter runs