求三角形外接圆圆心坐标的算法

时间:2021-11-03 09:45:42
///////////////////////////////////////////  
//求三角形外接圆圆心坐标  
///////////////////////////////////////////  
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);  

}