已知圆上三个点坐标,求圆半径 r 和 圆心坐标

问题:

已知圆上三个点坐标分别为(x1,y1)、(x2,y2)、(x3,y3)

求圆半径R和圆心坐标(X,Y)

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²-x2²-2*x1*X+2*x2*X+y12-y22-2*y1*Y+2*y2*Y=0
(2)-(3)整理得:
x2²-x3²-2*x2*X+2*x3*X+y22-y32-2*y2*Y+2y3*Y=0
再整理上面两式得
(2x2-2x1)X+(2y2-2y1)Y=x2²-x1²+y2²-y1²

(2x3-2x2)X+(2y3-2y2)Y=x3²-x2²+y3²-y2²

令:

a=2x3-2x2;b=2y3-2y2;c=x3²-x2²+y3²-y2²

e = 2x2-2x1;f=2y2-2y1;g=x2²-x1²+y2²-y1²

于是有

eX+fY=g

aX+bY=c

解得

X=(gb-cf)\(eb-af)

Y=(ag-ce)\(af-be)

R=sqrt((X-x1)*(X-x1)+(Y-y1)*(Y-y1))则圆心坐标为(X,Y),半径为R

程序实现:

void Calculate_cicular(Point px1, Point px2, Point px3)
{
int x1, y1, x2, y2, x3, y3;
int a, b, c, g, e, f;
x1 = px1.x;
y1 = px1.y;
x2 = px2.x;
y2 = px2.y;
x3 = px3.x;
y3 = px3.y;
e = 2 * (x2 - x1);
f = 2 * (y2 - y1);
g = x2*x2 - x1*x1 + y2*y2 - y1*y1;
a = 2 * (x3 - x2);
b = 2 * (y3 - y2);
c = x3*x3 - x2*x2 + y3*y3 - y2*y2;
X = (g*b - c*f) / (e*b - a*f);
Y = (a*g - c*e) / (a*f - b*e);
R = sqrt((X-x1)*(X-x1)+(Y-y1)*(Y-y1)); }

  

上一篇:2018.12.19 Struts2 框架总复习


下一篇:linux中sudoers别名规则