ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/cal/cal/circle.cal
Revision: 1.2
Committed: Wed Nov 21 18:10:45 2018 UTC (5 years, 5 months ago) by greg
Branch: MAIN
CVS Tags: rad5R4, rad5R3, HEAD
Changes since 1.1: +1 -0 lines
Log Message:
Added missing RCSid tag

File Contents

# User Rev Content
1 greg 1.2 { RCSid $Id$ }
2 greg 1.1 {
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));