Transformations
An isometry of the plane is one of four things: a translation, a rotation, a reflection or a glide reflection. With exact matrices the classification is a computation, and composing two maps and asking what you got is the quickest way to learn it.
const r = rotation([1, 1], "1/4"); // a quarter turn about (1, 1)
String(r.apply([2, 1])); // "(1, 2)"
const m = reflection(line([0, 0], [1, 1]));
m.compose(reflection(line([0, 0], [1, 0]))).classify(); // a rotation by 90° about the origin
glide(line([0, 0], [1, 0]), [3, 0]).classify(); // { kind: "glide reflection", axis, vector }
dilation([0, 0], 2).compose(r).classify().kind; // "spiral similarity"
inversion(circle([0, 0], { radius: 1 })).apply(line([2, 0], [2, 1])); // a circle through the centre
Exact angles
A rotation matrix needs a cosine and a sine. Given as a fraction of a full turn, rotation(c, "1/6"), they are the exact algebraic values ( and for a sixth of a turn). Or give any exact pair with , such as { cos: "3/5", sin: "4/5" }, which is checked. Rotating by a sixth of a turn six times gives back exactly the identity.
Classifying
Every map here is . classify() looks at M:
- : an isometry. With determinant +1 it is a translation (M = I) or a rotation, whose centre is the one fixed point. With determinant −1 it is a reflection if it has a line of fixed points, and otherwise a glide reflection: a reflection followed by a slide along the mirror.
- : a similarity with ratio k. It has exactly one fixed point, its centre: a dilation, a spiral similarity (dilation and rotation), or a dilative reflection.
- otherwise an affine map: lines stay lines and parallels stay parallel, but angles change; the determinant is the factor by which areas are multiplied.
fixed() returns the fixed points: a point, a line, the whole plane or none.
Two facts worth trying: reflections in two lines that meet compose to a rotation about the meeting point through twice the angle between them, and in two parallel lines to a translation through twice the distance. So every isometry is a product of at most three reflections.
Inversion
Inversion in a circle with centre O and radius r sends p to the point p′ on the ray Op with . It swaps inside and outside, fixes the circle, and sends lines and circles to lines and circles: a line through O to itself, a line missing O to a circle through O, and a circle through O to a line. inversion(c).apply(figure) returns the image exactly.
| call | returns |
|---|---|
| translation(v), rotation(centre, turn | { cos, sin }), reflection(line), glide(line, v), dilation(centre, k), affine(M, t), identity() | Transform |
| T.apply(point | line | circle | triangle | points) | the image |
| T.compose(U), T.inverse(), T.equals(U), T.determinant | T after U; the inverse |
| T.isIsometry(), T.isSimilarity(), T.fixed(), T.classify() | { kind, center, axis, vector, cos, sin, ratio, … } |
| inversion(circle).apply(point | line | circle) | the image |
@ratmath/geo and Core's Rational in scope. The last line's value is shown; PRINT(…) adds lines, TEX(…) typesets math.