Skip to content

Commit 9e03e20

Browse files
committed
circle by 3 points
1 parent 61362ba commit 9e03e20

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

3_point_circle.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
double x1,x2,x3,y1,y2,y3,x1sq,x2sq,x3sq,y1sq,y2sq,y3sq;
2+
cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
3+
x1sq = x1*x1;
4+
x2sq = x2*x2;
5+
x3sq = x3*x3;
6+
y1sq = y1*y1;
7+
y2sq = y2*y2;
8+
y3sq = y3*y3;
9+
double A , B , C , D;
10+
A = x1*(y2 - y3) - y1*(x2 - x3) + x2*y3 - x3*y2;
11+
B = ((x1sq + y1sq)*(y3 - y2))+((x2sq + y2sq)*(y1- y3)) + ((x3sq+y3sq)*(y2-y1));
12+
C = ((x1sq + y1sq)*(x2 - x3))+((x2sq + y2sq)*(x3- x1)) + ((x3sq+y3sq)*(x1-x2));
13+
D = ((x1sq + y1sq)*(x3*y2 - x2 * y3)) + ((x2sq + y2sq)*(x1*y3 -x3*y1)) + ((x3sq+y3sq)*(x2*y1-x1*y2));
14+
// Radius
15+
double r = sqrt((B*B + C*C - 4*A*D)/(4.0f*A*A));
16+
17+
// Center X-co-ordinate
18+
x = -(B / (2.0f*A))
19+
y = -(C / (2.0f*A))

0 commit comments

Comments
 (0)