已知: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为点的坐标