Topic

Points, lines, circles and constructions

The Euclidean plane has three kinds of object and two tools. Everything the tools can make has coordinates that are exact numbers, and this page is about those.

const l = line([0, 0], [2, 1]);              // or line(a, b, c) for ax + by + c = 0
const c = circle([0, 0], { radius: 1 });     // or circle(centre, pointOnIt)
meet(l, c);                                  // 0, 1 or 2 points, exact
perpendicularBisector([0, 0], [4, 0]);       // x − 2 = 0
regularPolygon(5);                           // five exact vertices on the unit circle

const k = construction({ A: [0, 0], B: [1, 0] });
k.circle("a", "A", "B").circle("b", "B", "A").meet(["C", "D"], "a", "b").line("m", "C", "D");
String(k.get("C"));                          // "(1/2, -√3/2)"

What the tools add

A ruler draws the line through two known points; a compass draws the circle with a known centre through a known point. New points appear where these meet. Two lines meet where two linear equations hold, which needs only +, −, ×, ÷. A line and a circle, or two circles, meet where a quadratic equation holds, which needs one square root more. So starting from rational points, every constructible coordinate is built from rationals by the four operations and square roots, however deep the nesting. These are algebraic numbers, and meet returns them exactly: the vertex of the regular pentagon is (−1+54,10+254)\bigl(\tfrac{-1+\sqrt5}{4}, \tfrac{\sqrt{10+2\sqrt5}}{4}\bigr).

Two circles meet on their radical axis, the line left when one circle's equation is subtracted from the other's, so that case reduces to a line and a circle.

Predicates

Because the numbers are exact, so are the questions asked of them: collinear, concyclic, concurrent, parallel, perpendicular, orientation (left turn, right turn or straight), circle.power(p) (negative inside, zero on, positive outside). None of them takes a tolerance.

A construction as a list of steps

construction(given) records a construction the way it is written in a textbook. Each step names what it makes: line(name, P, Q) uses the ruler, circle(name, centre, through) the compass (a third argument carries the radius |PQ| to another centre), and meet(names, f, g) marks intersections. count says how many times each tool was used, String(k) prints the steps, and get(name) returns any object with its exact coordinates.

Regular polygons

regularPolygon(n) uses the exact values of cos⁡(2πk/n)\cos(2\pi k/n) and sin⁡(2πk/n)\sin(2\pi k/n). For n = 3, 4, 5, 6, 8, 10, 12, 15, 17, … these are nested square roots, which is Gauss's theorem on which polygons are constructible. For n = 7 or 9 they are algebraic numbers of degree 3 that no nest of square roots expresses: still exact here, but out of the compass's reach.

callreturns
point(x, y), line(P, Q), line(a, b, c), circle(centre, through | { radius })Point, Line, Circle
meet(f, g)Point or null (two lines); Point[] ordered by x then y
distance, distance2, midpoint, foot(P, l), reflect(P, l)exact numbers and Points
parallelThrough(l, P), perpendicularThrough(l, P), perpendicularBisector(P, Q), angleBisector(A, V, B)Line
circumcircle(A, B, C), tangents(circle, P), regularPolygon(n, { center, vertex })Circle, Line[], Point[]
collinear, concyclic, concurrent, parallel, perpendicular, orientationexact predicates
construction(given).line(…).circle(…).meet(…)Construction: get(name), steps, count
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