{********************************************************* * Program to demonstrate Apollonius circles and clipping * * capability of unit CrtGr2D.pas * * * * TPW version by J-P Moreau, Paris * * (www.jpmoreau.fr) * * ------------------------------------------------------ * * DESCRIPTION: At each step, the program: * * 1. randomly defines 3 circles so that they are at * * least partially visible and each one is tangent * * to the other two. * * 2. recursively draws all the internal (apollonius) * * circles until radius is too small, using a fast * * procedure to draw circles. * * The number of steps is limited to 20 and the average * * drawing time of a step is constantly displayed. * * ------------------------------------------------------ * * INSTRUCTIONS: Press space bar to stop program after a * * step is over. * * * * NOTE: The print option is not implemented here * *********************************************************} Program Apollo; Uses WinCrtMy,WinProcs,Maths_2D,Graph_2,Type_def,CrtGr2D,Time; Type {object circle defined by center and 1/radius} cercle = Record centre: point2D; cb : real_ar; End; Var X_min,X_max,Y_min,Y_max: real_ar; C : Array [1..3] of cercle; i : 1..3; moyenne : real_ar; compte,err,j,k : integer; {returns true if circle is not entirely visible} Function horsLimites(C: cercle): boolean; Var r: real_ar; Begin With C,centre do begin r:=1/cb; horsLimites:=true; if (xX_max) and (rY_max) and (r c2.cb then begin Co:=c1; c1:=c2; c2:=Co end; if c2.cb > c3.cb then begin Co:=c2; c2:=c3; c3:=Co end; GetVecteur2D(c1.centre,c2.centre,V2); GetVecteur2D(c1.centre,c3.centre,V3); d:=V2.x*V3.y-V2.y*V3.x; Erreur2D:=abs(d)= c1.cb); If erreur2D then exit; a:=c/c1.cb; b:=1-a; c2.cb:=c/b; GetVecteur2D(c1.centre,c2.centre,V); c:=c/c3.cb; a:=a+c; b:=b+c; c:=(sqr(a)-sqr(b)+1)/2.0; a:=sqrt(sqr(a)-sqr(c)); c3.centre:=c1.centre; With c3.centre do begin x:=x+V.x*c+a*V.y; y:=y+V.y*c-a*V.x end End; {main program} BEGIN Randomize; x_min:=-0.60; y_min:=-0.45; x_max:=0.60; y_max:=0.45; WinCrtInit('APOLLONIUS CIRCLES'); Fenetre(x_min,x_max,y_min,y_max); Cloture(70,MaxX-30,95,MaxY-5); StartTiming; rep:='o'; Repeat compte:=0; Repeat ClrScr; Axes(CrtDC); Grille(CrtDC,0.1,0.05); Gradue(CrtDC,0.2,0.10); Bordure(CrtDC); Repeat Inc(compte); gotoxy(62,2); write(compte:2); With C[1] do begin centre.x := 1.0*Random-1.0; centre.y := 0.5*Random-1.25; cb := 1.0*Random+0.3; end; With C[2].centre do begin x:=1.0*Random-1.0; y:=0.5*Random+0.5; end; C[3].cb:=1.0*Random+0.3; TroisiemeCercle(C[1],C[2],C[3]); Until Not Erreur2D; For i:=1 to 3 do traceCercle(C[i]); TraceInterne(C[1],C[2],C[3]); StopTiming; Val(Elapsed,moyenne,err); moyenne:=moyenne/compte; gotoxy(12,2); write('Mean time: ',moyenne:6:1,' s.'); for j:=1 to 30000 do {waiting loop} for k:=1 to 3000 do; Until (compte>19) or Keypressed; SortieGraphique Until rep='n'; DoneWinCrt END. {end of file apollo.pas}