(* This figure demonstrates a geometric theorem discovered by Leonard Euler. In any triangle, it is well-known that the three altitudes (the red lines in the figure) intersect in a point P, and that the three perpendicular bisectors (the blue lines in the figure) intersect in a point Q. Let C (the green point) be the midpoint of the segment PQ (shown in grey). Then C is the center of a circle on which lie the following 6 points: the 3 midpoints of the triangle's edges and the 3 points where the triangle's altitudes intersect the opposite edges. *) CONST LightColor = Color.Grey50, LightWidth = 1.5; FUNC d = PerpPoint(a, b, c) IS (E x = (100, 0) REL (a, b) :: Angle.Right(x, d, c) AND Geometry.Colinear(a, d, x)) END; UI PointTool(PerpPoint); PROC DrawPerp(a, b, c) IS IF VAR d ~ (0.1, 0) REL (b, c), f ~ (0.1, 0) REL (b, a) IN Geometry.Colinear(a, f, b) AND Geometry.Colinear(b, d, c) AND (f, b) CONG (b, d) AND Geometry.Dist(f, b) = 10 -> IF VAR e ~ (0.5, 0.2) REL (f, b) IN (f, e) PARA (b, c) AND (a, b) PARA (e, d) -> SAVE PS IN PS.SetWidth(LightWidth); PS.MoveTo(c); PS.LineTo(b); PS.MoveTo(d); PS.LineTo(e); PS.LineTo(f); PS.MoveTo(a); PS.LineTo(b); PS.Stroke() END END FI END FI END; UI PointTool(DrawPerp); PROC Connect3(a, b, c) IS SAVE PS IN PS.MoveTo(a); PS.LineTo(c); PS.LineTo(b); PS.SetWidth(LightWidth); PS.Stroke() END END; UI PointTool(Connect3); PROC Cmd0() IS IF VAR a = (-115.1, -162.3), b = (146.2, -106.9), c = (-7.574, 142.6), d ~ (15.54, -134.6), e ~ (69.3, 17.82), f ~ (-61.34, -9.852), g ~ (49.63, -127.4), h ~ (99, -30.39), i ~ (-68.84, -31.12), j ~ (37.15, -68.5), k ~ (-6.823, -29.08), l ~ (15.16, -48.79) IN d = Geometry.Mid(a, b) AND e = Geometry.Mid(b, c) AND f = Geometry.Mid(a, c) AND g = PerpPoint(a, b, c) AND h = PerpPoint(b, c, a) AND i = PerpPoint(c, a, b) AND Geometry.Colinear(c, j, g) AND Geometry.Colinear(i, j, b) AND Angle.Right(a, d, k) AND Angle.Right(c, f, k) AND l = Geometry.Mid(j, k) -> SAVE PS IN PS.SetColor(Color.FromHSV(Color.RedHue, 0.5, 1)); DrawPerp(a, g, c); DrawPerp(b, h, a); DrawPerp(c, i, b); Connect3(b, i, j); Connect3(c, g, j); Connect3(a, h, j) END; SAVE PS IN PS.SetColor(Color.FromHSV(Color.BlueHue, 0.5, 1)); DrawPerp(a, d, k); DrawPerp(c, f, k); DrawPerp(b, e, k) END; SAVE PS IN Triangle.Draw(a, b, c); PS.SetWidth(2); PS.Stroke() END; SAVE PS IN PS.MoveTo(j); PS.LineTo(k); PS.SetWidth(1.5 * LightWidth); PS.SetColor(Color.Grey50); PS.Stroke() END; PtLabel.SetDotSize(4); SAVE PS IN PS.SetColor(Color.FromHSV(Color.GreenHue, 0.8, 0.5)); PtLabel.None(l); Circle.Draw(l, e); PS.Stroke(); PS.SetColor(Color.Red); PtLabel.None(i); PtLabel.None(h); PtLabel.None(g); PtLabel.None(j); PS.SetColor(Color.Blue); PtLabel.None(d); PtLabel.None(e); PtLabel.None(f); PtLabel.None(k) END END FI END;