struct Circle Circle3(struct Point *a, struct Point *b, struct Point *c) //三点定圆
{
struct Circle p;
double K1, K2;
double a1, b1, c1, d1, e, f, det, x0, y0;
a1 = a->x - b->x;
b1 = a->y - b->y;
c1 = a->x - c->x;
d1 = a->y - c->y;
if (a1 == 0 && c1 == 0)
{
cout << "error!" << endl;
exit(-1);
}
K1 = a1 / b1;
K2 = c1 / d1;
if (K1 == K2)
{
cout << "error!" << endl;
exit(-1);
}
e = ((a->x * a->x - b->x * b->x) + (a->y * a->y - b->y * b->y)) / 2.0;
f = ((a->x * a->x - c->x * c->x) + (a->y * a->y - c->y * c->y)) / 2.0;
det = b1 * c1 - a1 * d1;
if (fabs(det) < 1e-5)
{
cout << "error!" << endl;
exit(-1);
}
x0 = -(d1 * e - b1 * f) / det;
y0 = -(a1 * f - c1 * e) / det;
p.CR = hypot(a->x - x0, a->y - y0);
p.CX = x0;
p.CY = y0;
return p;
}
三点定圆
最新推荐文章于 2021-12-02 23:24:18 发布