double dis(Point a) { return a.x*a.x+a.y*a.y; } struct Circle Circumcircle() { Circle tmp; double a,b,c,c1,c2; double xa,ya,xb,yb,xc,yc; a = sqrt(dis(p[3]-p[1])); b = sqrt(dis(p[1]-p[2])); c = sqrt(dis(p[2]-p[3])); //根据s = a*b*c/R/4,求半径 tmp.r = (a*b*c)/(area()*4.0); xa = p[3].x; ya = p[3].y; xb = p[1].x; yb = p[1].y; xc = p[2].x; yc = p[2].y; c1 = (dis(p[3])-dis(p[1]))/2; c2 = (dis(p[3])-dis(p[2]))/2; tmp.center.x = (c1*(ya-yc)-c2*(ya-yb))/((xa-xb)*(ya-yc)-(xa-xc)*(ya-yb)); tmp.center.y = (c1*(xa-xc)-c2*(xa-xb))/((ya-yb)*(xa-xc)-(ya-yc)*(xa-xb)); return tmp; }
原文地址:http://www.cnblogs.com/shangyu/p/3825183.html