首页 > 其他 > 详细

外接圆模板

时间:2014-07-06 17:39:05      阅读:234      评论:0      收藏:0      [点我收藏+]
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;
}

 

外接圆模板,布布扣,bubuko.com

外接圆模板

原文:http://www.cnblogs.com/shangyu/p/3825183.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!