三点求圆心以及半径
程序员文章站
2022-04-03 23:19:25
...
三点求圆心以及半径模板
double X,Y,R;
struct Point{
double x,y;
}pp[maxn];
double dis(Point x,Point y)
{
return sqrt((x.x-y.x)*(x.x-y.x)+(x.y-y.y)*(x.y-y.y));
}
void solve(Point a,Point b,Point c)//三点共圆圆心公式
{
X=( (a.x*a.x-b.x*b.x+a.y*a.y-b.y*b.y)*(a.y-c.y)-(a.x*a.x-c.x*c.x+a.y*a.y-c.y*c.y)*(a.y-b.y) ) / (2*(a.y-c.y)*(a.x-b.x)-2*(a.y-b.y)*(a.x-c.x));
Y=( (a.x*a.x-b.x*b.x+a.y*a.y-b.y*b.y)*(a.x-c.x)-(a.x*a.x-c.x*c.x+a.y*a.y-c.y*c.y)*(a.x-b.x) ) / (2*(a.y-b.y)*(a.x-c.x)-2*(a.y-c.y)*(a.x-b.x));
R=sqrt((X-a.x)*(X-a.x)+(Y-a.y)*(Y-a.y));
//return (Point){x,y};
}
下一篇: 2017自媒体账号申请及运营的几点建议