%geo.mf;  assumes gnuchars.mf has been loaded.
input gnuchars; %otherwise, add this
%%Make a special format: {\tt \obeywhitespace \medskip
%%inimf plain$\b$; input modes$\b$; input gnuchars$\b$; dump
%%mv plain.base /usr/TeX/lib/mf/bases/gmf.base
%%ln -s /usr/TeX/bin/virmf /usr/TeX/bin/gmf
%%gmf geo}

%%Now that we know how to embed characters in \mf, let's do a bit of
%%geometry.  At the beginning of his {\it Elements,} Euclid shows that
%%the local symmetry of space (ie the postulated constructibility of
%%circles) leads to the global property that lengths can be `moved.'
%%First some preliminaries:

screenstrokes; path p[];
pair A,B,C,D,E,F,G,H;
 pickup pencircle scaled .06pt;
 spen=savepen;
 pickup pencircle scaled .12pt;
 mpen=savepen;

%%We want to:

put_text("Given A, B, C, construct segment at C of length AB",0,450,0,1);
showit; sscreen(80pt#,80pt#,2pt#,1);

%%\font\geofont=geo
%%Recall that the {\tt gnuchars.mf} file defined {\tt
%%put\_text(<string>, <x-coord>, <y-coord>, <rotation:0, 90, 180,
%%or270>, <justification: 1,2,3 (left, center, right)>)}. I pick
%%convenient generic points and then shift for my specific screen:

A:=(50,50); B:=(60,-5); C:=(170,60); 
currenttransform:=identity shifted (90,20);
pickup mpen; 
drawdot A; put_text("A",xpart A,ypart A+10,0,2); showit;
drawdot B; put_text("B",xpart B+4,ypart B,0,1); showit;
drawdot C; put_text("C",xpart C, ypart C +12,0,2); showit;
draw A--B; 

%%To begin, we make use of Euclid's first theorem to:

put_text("1. Construct equilateral ACD and circle A(B)",0,420,0,1); 
showit;
sscreen(80pt#,80pt#,2pt#,1);

%%\vglue .2in\line{\hfil\hfil\geofont B\hfil}\vglue .2in
%%To do this, we need a `compass,' a way to, given a center and a
%%point on the circumference, define a circle. Often in defining \mf\
%%macros, parentheses are needed to make \mf\ parse the macro
%%correctly.  For example,

def gcircle (expr wa,wb) = 
  fullcircle scaled (2*length(wa-wb)) shifted wa enddef;

%%In Euclidean geometry, lines intersect in points; however, lines
%%weren't thought of as a potentially incomplete set of points. Hence,

D:=gcircle(A,C) intersectionpoint gcircle(C,A);

%%\noindent obviously exists. Moreover, {\tt AD=AC} as radii of {\tt
%%gcircle(A,C)}; similarly, {\tt AC=CD} so {\tt AD=CD} since things
%%equal to the same thing are the same.

%%To illustrate this construction, we need another macro to draw arcs
%%such as we would draw with a compass. Knowing where the intersection
%%is, we can make the arcs short. The {\tt garc} macro expands to a
%%three point curve.

def garc (expr wa,wb,d) = 
  wb rotatedaround (wa,d)..wb..wb rotatedaround (wa,-d) enddef;
pickup spen; draw garc(A,D,5);draw garc(C,D,5);
pickup mpen;drawdot D;
put_text("D",xpart D,ypart D +20, 0,2); showit;

%%Our idea is to use {\tt gcircle(A,B)} to rotate {\tt AB} until we
%%can slide it up a line to {\tt D} and then down to {\tt C}. Such
%%sliding might change the length of the segment so instead we appeal
%%to properties of circles.

pickup spen; draw gcircle(A,B);
put_text("2. Extend DA to E on A(B) and construct D(E)",0,400,0,1);
showit;
sscreen(80pt#,80pt#,2pt#,1);

%%\vglue .2in\line{\hfil\hfil\geofont C\hfil}\vglue .2in

%%Since we're using \mf\ to merely illustrate the abstract proof, it
%%is convenient to have another circle macro:

def grcircle (expr wa,r) = fullcircle scaled (2*r) shifted wa enddef;

r:=length(A-D)+length(A-B);
p1:=grcircle(D,r); 
draw p1;

%%The point {\tt E} is where {\tt A(B)} intersects {\tt p1}. However, due to
%%rounding errors, {\tt E} needs to be specified differently. We
%%instead make use of the fact that the direction in which a point on
%%a circle is traveling, the tangent, is perpendicular to a radius at
%%that point:

F=(A-D) rotated 90;
t:=directiontime F of p1; E=point t of p1; drawdot E;

%show E; uncomment following for proof of rounding error.
%show p1 intersectionpoint gcircle(A,B);

put_text("E",xpart E+8,ypart E-8,0,3); showit;

draw D--E; pickup mpen; draw A--E;
put_text("3. Extend DC to H on D(E), then CH is segment.",0,380,0,1);
showit;
sscreen(80pt#,80pt#,2pt#,1);

%%\vglue .2in\line{\hfil\hfil\geofont D\hfil}\vglue .2in
%We repeat the above procedure for {\tt H}.

G=(C-D) rotated 90;
t:=directiontime G of p1; H=point t of p1;

pickup spen; draw D--H; 
draw gcircle(D,C); 
pickup mpen; drawdot H;
put_text("H",xpart H +5,ypart H,0,1); showit;

draw C--H;
sscreen(80pt#,80pt#,2pt#,1);

%%\vglue .2in\line{\hfil\hfil\geofont E\hfil}\vglue .2in

%%As radii, DH=DE so, subtracting the equilateral's sides DC=AC, we
%%have CH=AE. Thus CH=AB and the construction is complete.
end;
