.geometry "version 0.40";
.l0; 
.text("The Euler Line", .l0);
.text("In any triangle, the orthocenter (Ort), the
center of mass (CM), and the circumcenter (Cir) all lie
on a line.  The distance between the CM and the Cir
is half the distance between the CM and the Ort.", .l0);
.text("From \triangleABC, form the superior triangle \triangleA'B'C'
by drawing a line through A parallel to BC, through
B parallel to AC and through C parallel to AB.", .l1);
.text("\triangleA'B'C' is similar to \triangleABC, is
twice the size, and is rotated 180\degrees.", .l2);
.text("Also, the circumcenter of the superior triangle
is the same as the orthocenter of the original triangle.", .l3);
.text("Press 'Run Script' to rotate \triangleABC by 180\degrees
and then to scale it to twice the size, so the rotated and
scaled triangle will coincide with the superior triangle of
the original.", .l4);
.text("Since a 180\degrees rotation about the CM followed
by a scale by a factor of 2 takes Cir to Ort, it is clear
that Cir, CM, and Ort lie on a line.", .l5);
f = .script(0.000000, 360.000000, 1.000000);
v1 = .free(0.0650888, -0.223373, "A");
v2 = .free(0.278107, 0.0251479, "B");
v3 = .free(-0.292899, 0.211538, "C");
l1 = .l.vv(v1, v2);
l2 = .l.vv(v2, v3);
l3 = .l.vv(v3, v1);
l4 = .l.vlpar(v3, l1, .in);
l5 = .l.vlpar(v2, l3, .in);
l6 = .l.vlpar(v1, l2, .in);
l10 = .l.vlperp(v1, l2, .in);
l11 = .l.vlperp(v2, l3, .in);
l12 = .l.vlperp(v3, l1, .in);
v7 = .v.ll(l10, l11, .red, "Ort");
v4 = .v.ll(l5, l6, "C'");
v5 = .v.ll(l6, l4, "B'");
v6 = .v.ll(l4, l5, "A'");
l7 = .l.vv(v5, v6);
l8 = .l.vv(v6, v4);
l9 = .l.vv(v4, v5);
l13 = .l.vv(v7, v2, .red);
l14 = .l.vv(v7, v1, .red);
l15 = .l.vv(v7, v3, .red);
v8 = .v.vvmid(v1, v2, .in);
v9 = .v.vvmid(v2, v3, .in);
v10 = .v.vvmid(v3, v1, .in);
l16 = .l.vlperp(v9, l2, .in);
l17 = .l.vlperp(v10, l3, .in);
l18 = .l.vlperp(v8, l1, .in);
v11 = .v.ll(l17, l16, .green, "Cir");
l19 = .l.vv(v11, v8, .green);
l20 = .l.vv(v11, v9, .green);
l21 = .l.vv(v11, v10, .green);
l22 = .l.vv(v1, v9, .in);
l23 = .l.vv(v3, v8, .in);
v12 = .v.ll(l22, l23, .yellow, "CM");
cmx = .f.vxcoord(v12);
cmy = .f.vycoord(v12);
id = .x.identity();
ncmx = .f.rpn(cmx, -1.000000, .mul);
ncmy = .f.rpn(cmy, -1.000000, .mul);
x1 = .x.translate(id, ncmx, ncmy);
x2 = .x.rotate(x1, f);
x3 = .x.rotate(x1, 180.000000);
sc = .f.rpn(f, 180.000000, .sub, 180.000000, .div, 
        1.000000, .add);
x4 = .x.scale(x3, sc, sc);
choice = .f.rpn(180.000000, f, .gt);
x5 = .x.xxf(x2, x4, choice);
x = .x.translate(x5, cmx, cmy);
av1 = .v.vx(v1, x, "A");
av2 = .v.vx(v2, x, "B");
av3 = .v.vx(v3, x, "C");
al1 = .l.vv(av1, av2);
al2 = .l.vv(av2, av3);
al3 = .l.vv(av3, av1);
al4 = .l.vlpar(av3, al1, .in);
al5 = .l.vlpar(av2, al3, .in);
al6 = .l.vlpar(av1, al2, .in);
al10 = .l.vlperp(av1, al2, .in);
al11 = .l.vlperp(av2, al3, .in);
al12 = .l.vlperp(av3, al1, .in);
av7 = .v.ll(al10, al11, .in, "Ort");
av4 = .v.ll(al5, al6, "C'");
av5 = .v.ll(al6, al4, "B'");
av6 = .v.ll(al4, al5, "A'");
al7 = .l.vv(av5, av6);
al8 = .l.vv(av6, av4);
al9 = .l.vv(av4, av5);
al13 = .l.vv(av7, av2, .in);
al14 = .l.vv(av7, av1, .in);
al15 = .l.vv(av7, av3, .in);
av8 = .v.vvmid(av1, av2, .in);
av9 = .v.vvmid(av2, av3, .in);
av10 = .v.vvmid(av3, av1, .in);
al16 = .l.vlperp(av9, al2, .in, .longline);
al17 = .l.vlperp(av10, al3, .in, .longline);
al18 = .l.vlperp(av8, al1, .in, .longline);
av11 = .v.ll(al17, al16, .green, "Cir");
al19 = .l.vv(av11, av8, .green);
al20 = .l.vv(av11, av9, .green);
al21 = .l.vv(av11, av10, .green);
al22 = .l.vv(av1, av9, .in);
al23 = .l.vv(av3, av8, .in);
av12 = .v.ll(al22, al23, .yellow, "CM");
.text("Type 'Next' to continue ...", .red, .tol4);
l24 = .l.vv(v11, v7, .magenta, .l0);
