The projective plane
Add to the plane one point at infinity for each direction, and a line through them all. Then any two lines meet, any two points lie on one line, and points and lines can trade places in every statement.
const A = ppoint(0, 0), B = ppoint(1, 0); // [0 : 0 : 1], [1 : 0 : 1]
join(A, B); // the line [0 : 1 : 0], that is y = 0
meetLines(join([0, 0], [1, 1]), join([0, 1], [1, 2])); // [1 : 1 : 0], at infinity
crossRatio([0, 0], [1, 0], [2, 0], [5, 0]); // 8/5
projectivityFrom(fourPoints, fourImages); // the one projective map that does it
conicThrough([[5, 0], [3, 4], [-4, 3], [0, -5], [4, -3]]).classify(); // "circle"
pascal(sixPointsOnAConic).holds; // true
Homogeneous coordinates
The point (x, y) is written [x : y : 1], and any non-zero multiple [λx : λy : λ] is the same point. Triples with last coordinate 0 are the points at infinity: [a : b : 0] is where all lines with direction (a, b) meet. A line is the triple [a : b : c], and the point [x : y : z] is on it exactly when .
The line through two points is their cross product, and so is the point on two lines. This is duality: every true statement about points and lines stays true when the words are swapped, and p.dual turns one into the other. Two parallel lines are no exception: they meet at a point of the line at infinity, lineAtInfinity().
The cross-ratio
Lengths and angles do not survive a projective map, but one number does. For four points on a line,
where [PQ] is a 2 × 2 determinant of the homogeneous coordinates, and for ordinary points it is the ratio of signed lengths . With exact coordinates it comes out as an exact rational, and it is the same after any projective map. When it is −1 the four points are harmonic; harmonicConjugate(A, B, C) finds the fourth.
Projective maps
An invertible 3 × 3 matrix acts on homogeneous coordinates and sends lines to lines. Two matrices that differ by a factor are the same map, so the library scales each to a standard form. The fundamental theorem says four points in general position (no three on a line) can be sent to any other four by exactly one projective map; projectivityFrom builds it, by sending the standard frame [1:0:0], [0:1:0], [0:0:1], [1:1:1] to each set.
Conics
A conic is for a symmetric matrix C, and five points with no four on a line fix exactly one. conicThrough solves the linear system exactly. The polar of a point p is the line Cp, which for p on the conic is the tangent; the pole of a line is . In the projective plane every non-degenerate real conic is the same, and the affine kinds differ only in how they meet the line at infinity: an ellipse misses it, a parabola touches it, a hyperbola crosses it. classify reads this from the signs of two determinants.
Four theorems, checked on exact figures
- Desargues. Two triangles are in perspective from a point exactly when they are in perspective from a line.
- Pappus. With A, B, C on one line and a, b, c on another, the points Ab·aB, Ac·aC, Bc·bC are collinear.
- Pascal. For a hexagon inscribed in a conic, the three meets of opposite sides are collinear. Pappus is the case of a conic that is two lines.
- Brianchon. For a hexagon circumscribed about a conic, the three main diagonals meet in a point: Pascal's dual.
Each function takes a figure, builds the lines and points exactly, and reports whether the conclusion holds together with the points it found. These are checks on one figure; proofs in general are the elimination phase still to come.
| call | returns |
|---|---|
| ppoint(x, y) or ppoint(x, y, z), pline(a, b, c), lineAtInfinity() | PPoint, PLine: coords, equals, dual, atInfinity, toAffine() |
| join(p, q), meetLines(l, m), collinearP, concurrentP | The line through two points, the point on two lines |
| crossRatio(a, b, c, d), harmonicConjugate(a, b, c) | An exact number (or "infinity"); a PPoint |
| projectivity(matrix), projectivityFrom(from, to) | Projectivity: apply (points and lines), compose, inverse, isAffine |
| conicThrough(points), Conic.fromCoefficients([a, b, c, d, e, f]) | Conic: contains, polar, pole, tangentAt, transform, classify |
| desargues(t1, t2), pappus(abc, ABC), pascal(six), brianchon(conic, six) | { holds, … the points and lines found } |
@ratmath/geo and Core's Rational in scope. The last line's value is shown; PRINT(…) adds lines, TEX(…) typesets math.