码迷,mamicode.com
首页 > 其他好文 > 详细

外接圆模板

时间:2014-07-06 17:39:21      阅读:153      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   div   ar   re   

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

外接圆模板

标签:style   blog   color   div   ar   re   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!