Subject 1.04: How do I generate a circle through three points? Let the three given points be a, b, c. Use _0 and _1 to represent x and y coordinates. The coordinates of the center p=(p_0,p_1) of the circle determined by a, b, and c are: A = b_0 - a_0; B = b_1 - a_1; C = c_0 - a_0; D = c_1 - a_1;
E = A*(a_0 + b_0) + B*(a_1 + b_1); F = C*(a_0 + c_0) + D*(a_1 + c_1);
G = 2.0*(A*(c_1 - b_1)-B*(c_0 - b_0));
p_0 = (D*E - B*F) / G; p_1 = (A*F - C*E) / G;
If G is zero then the three points are collinear and no finite-radius circle through them exists. Otherwise, the radius of the circle is: r^2 = (a_0 - p_0)^2 + (a_1 - p_1)^2 Reference: [O' Rourke (C)] p. 201. Simplified by Jim Ward.
楼主多看看书!
circle(x,y,z);
x and y coordinates. The coordinates of the center p=(p_0,p_1) of
the circle determined by a, b, and c are: A = b_0 - a_0;
B = b_1 - a_1;
C = c_0 - a_0;
D = c_1 - a_1;
E = A*(a_0 + b_0) + B*(a_1 + b_1);
F = C*(a_0 + c_0) + D*(a_1 + c_1);
G = 2.0*(A*(c_1 - b_1)-B*(c_0 - b_0));
p_0 = (D*E - B*F) / G;
p_1 = (A*F - C*E) / G;
If G is zero then the three points are collinear and no finite-radius
circle through them exists. Otherwise, the radius of the circle is: r^2 = (a_0 - p_0)^2 + (a_1 - p_1)^2 Reference: [O' Rourke (C)] p. 201. Simplified by Jim Ward.
//求三角形外接圆圆心坐标
///////////////////////////////////////////
void circle_center(Point *center,Point pt[3],double *radiu)
{
double x1,x2,x3,y1,y2,y3;
double x = 0;
double y = 0; x1 = pt[0].pt.x;
x2 = pt[1].pt.x;
x3 = pt[2].pt.x;
y1 = pt[0].pt.y;
y2 = pt[1].pt.y;
y3 = pt[2].pt.y; x=((y2-y1)*(y3*y3-y1*y1+x3*x3-x1*x1)-(y3-y1)*(y2*y2-y1*y1+x2*x2-x1*x1))/(2*(x3-x1)*(y2-y1)-2*((x2-x1)*(y3-y1)));
y=((x2-x1)*(x3*x3-x1*x1+y3*y3-y1*y1)-(x3-x1)*(x2*x2-x1*x1+y2*y2-y1*y1))/(2*(y3-y1)*(x2-x1)-2*((y2-y1)*(x3-x1))); center->pt.x = x ;
center->pt.y = y ;
*radiu = (pt[0].pt.x - x)*(pt[0].pt.x - x) + (pt[0].pt.y - y)*(pt[0].pt.y - y);}