1 |
{ RCSid $Id$ } |
2 |
{ |
3 |
Calculate center and radius of circle based on three |
4 |
points in the plane. |
5 |
|
6 |
Beware colinear points and points parallel to y-axis. |
7 |
|
8 |
6/4/2002 Greg Ward |
9 |
solution due to Paul Bourke |
10 |
|
11 |
Inputs: |
12 |
|
13 |
x1,y1,x2,y2,x3,y3 - points on circle |
14 |
|
15 |
Outputs: |
16 |
|
17 |
xc, yc, r - center and radius |
18 |
} |
19 |
sq(x) : x*x; |
20 |
|
21 |
ma = (y2-y1)/(x2-x1); |
22 |
mb = (y3-y2)/(x3-x2); |
23 |
|
24 |
xc = (ma*mb*(y1-y3) + mb*(x1+x2) - ma*(x2+x3)) / (2*(mb-ma)); |
25 |
|
26 |
yc = ((x1+x2)/2 - xc)/ma + (y1+y2)/2; |
27 |
|
28 |
r = sqrt(sq(x2-xc) + sq(y2-yc)); |