home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / library / dos / bix / cenrad.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1986-08-04  |  1.1 KB  |  34 lines

  1. {Turbo/Generic Determining Center & Radius of Circle from 3 Points.
  2. ***with special thanks to Gary 'gkendall' Kendall and Claus 'claus_m'
  3.    Makowa for their contributions in Grafic.pgms/other. This version is
  4.    about twice the speed of the version in Pascal/Source #13.  - Jim}
  5.  
  6. function cir3pt(p1,p2,p3:pt;var c:cir):boolean;
  7. var        cx,cy,xy1,xx1,xx2,xx3,yy1,yy2,yy3,i,j,A,B,D:real;
  8. begin
  9.  xx1 := p1.x;  xx1 := xx1*xx1;
  10.  xx2 := p2.x;  xx2 := xx2*xx2;
  11.  xx3 := p3.x;  xx3 := xx3*xx3;
  12.  yy1 := p1.y;  yy1 := yy1*yy1;
  13.  yy2 := p2.y;  yy2 := yy2*yy2;
  14.  yy3 := p3.y;  yy3 := yy3*yy3;
  15.  xy1 := xx1 + yy1;
  16.  D :=           1.0 * (p3.x - p2.x) * p1.y
  17.               + 1.0 * (p2.x - p1.x) * p3.y
  18.               + 1.0 * (p1.x - p3.x) * p2.y;
  19.  if D = 0.0 then cir3pt:=false else
  20.   begin
  21.    D := D+D;
  22.    cir3pt:=true;
  23.    A := xy1 - xx2 - yy2;
  24.    B := xy1 - xx3 - yy3;
  25.    cx := ( A * (p1.y - p3.y) - B * (p1.y - p2.y) ) / D;
  26.    cy := ( B * (p1.x - p2.x) - A * (p1.x - p3.x) ) / D;
  27.    i:=cx-p1.x;
  28.    j:=cy-p1.y;
  29.    c.r:=round(sqrt(i*i+j*j));
  30.    c.x := round(cx);
  31.    c.y := round(cy)
  32.    end;
  33. end;
  34.