ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/cal/cal/circle.cal
Revision: 1.1
Committed: Sat Feb 22 02:07:21 2003 UTC (21 years, 2 months ago) by greg
Branch: MAIN
CVS Tags: rad5R2, rad4R2P2, rad5R0, rad5R1, rad3R7P2, rad3R7P1, rad4R2, rad4R1, rad4R0, rad3R5, rad3R6, rad3R6P1, rad3R8, rad3R9, rad4R2P1
Log Message:
Changes and check-in for 3.5 release
Includes new source files and modifications not recorded for many years
See ray/doc/notes/ReleaseNotes for notes between 3.1 and 3.5 release

File Contents

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