已知圆上三点坐标求圆心

//求圆心坐标
    getCenterPos:function(x1,y1,x2,y2,x3,y3){
        var a=2*(x2-x1);
        var b=2*(y2-y1);
        var c=x2*x2+y2*y2-x1*x1-y1*y1;
        var d=2*(x3-x2);
        var e=2*(y3-y2);
        var f=x3*x3+y3*y3-x2*x2-y2*y2;
        var x=(b*f-e*c)/(b*d-e*a);
        var y=(d*c-a*f)/(b*d-e*a);
        cc.log("x:"+x+"y:"+y);
        r=sqrt((x-x1)*(x-x1)+(y-y1)*(y-y1));//半径
    },

你可能感兴趣的:(cocos-js)