通过圆上点计算圆心与半径
因为工作中,用到了所以找了下,挺不错,分享一下。
就是解三元二次方程组!
X,Y,R为未知数,x1,y1,x2,y2,x3,y3为常数
(x1-X)²-(y1-Y)²=R² (1)式
(x2-X)²-(y2-Y)²=R² (2)式
(x3-X)²-(y3-Y)²=R² (3)式
(1)-(2),就是左边减左边,右边减右边,得到
x1²-2Xx1+X²-(y1²-2Yy1+Y²)-(x2²-2Xx2+X²)+(y2²-2Yy2+Y²)=R²-R²
整理得
x1²+y2²-y1²-x2²+2Xx2-2Xx1+2Yy1-2Yy2=0
(2)-(1)整理得:
x2²+y3²-y2²-x3²+2Xx3-2Xx2+2Yy2-2Yy3=0
再整理上面两式得
(2×2-2×1)X+(2y1-2y2)Y=y1²+x2²-x1²-y2²
(2×3-2×2)X+(2y2-2y3)Y=y2²+x3²-x2²-y3²
程序问题:
a=2*(x2-x1);
b=2*(y2-y1);
c=x2*x2+y2*y2-x1*x1-y1*y1;
d=2*(x3-x2);
e=2*(y3-y2);
f=x3*x3+y3*y3-x2*x2-y2*y2;
x=(b*f-e*c)/(b*d-e*a);
y=(d*c-a*f)/(b*d-e*a);
r=sqrt((x-x1)*(x-x1)+(y-y1)*(y-y1));
其中:变量和常量都为双精度型(double)
转载自:https://blog.csdn.net/qisefengzheng/article/details/47278829