任意三点求圆心算法

已知:startPoint、secondPoint、endPoint(不分先后)

求:圆心坐标

解:

var tempA1,tempA2,tempB1,tempB2,tempC1,tempC2,temp,x,y;

tempA1=startPoint.x-secondPoint.x; 

tempB1=startPoint.y-secondPoint.y;
tempC1=(Math.pow(startPoint.x,2)-Math.pow(secondPoint.x,2)+Math.pow(startPoint.y,2)-Math.pow(secondPoint.y,2))/2;
  
tempA2=endPoint.x-secondPoint.x;
tempB2=endPoint.y-secondPoint.y;
tempC2=(Math.pow(endPoint.x,2)-Math.pow(secondPoint.x,2)+Math.pow(endPoint.y,2)-Math.pow(secondPoint.y,2))/2;
        
temp=tempA1*tempB2-tempA2*tempB1;
if(temp==0){
    x=startPoint.x;
    y=startPoint.y;
}else{
    x=(tempC1*tempB2-tempC2*tempB1)/temp;
    y=(tempA1*tempC2-tempA2*tempC1)/temp;
}
new Point(x,y); //x  y为点的坐标

 

 
posted @ 2013-04-22 18:02  天边的星星  阅读(2071)  评论(0编辑  收藏  举报