home *** CD-ROM | disk | FTP | other *** search
- {Turbo/Generic Determining Center & Radius of Circle from 3 Points.
- ***with special thanks to Gary 'gkendall' Kendall and Claus 'claus_m'
- Makowa for their contributions in Grafic.pgms/other. This version is
- about twice the speed of the version in Pascal/Source #13. - Jim}
-
- function cir3pt(p1,p2,p3:pt;var c:cir):boolean;
- var cx,cy,xy1,xx1,xx2,xx3,yy1,yy2,yy3,i,j,A,B,D:real;
- begin
- xx1 := p1.x; xx1 := xx1*xx1;
- xx2 := p2.x; xx2 := xx2*xx2;
- xx3 := p3.x; xx3 := xx3*xx3;
- yy1 := p1.y; yy1 := yy1*yy1;
- yy2 := p2.y; yy2 := yy2*yy2;
- yy3 := p3.y; yy3 := yy3*yy3;
- xy1 := xx1 + yy1;
- D := 1.0 * (p3.x - p2.x) * p1.y
- + 1.0 * (p2.x - p1.x) * p3.y
- + 1.0 * (p1.x - p3.x) * p2.y;
- if D = 0.0 then cir3pt:=false else
- begin
- D := D+D;
- cir3pt:=true;
- A := xy1 - xx2 - yy2;
- B := xy1 - xx3 - yy3;
- cx := ( A * (p1.y - p3.y) - B * (p1.y - p2.y) ) / D;
- cy := ( B * (p1.x - p2.x) - A * (p1.x - p3.x) ) / D;
- i:=cx-p1.x;
- j:=cy-p1.y;
- c.r:=round(sqrt(i*i+j*j));
- c.x := round(cx);
- c.y := round(cy)
- end;
- end;
-