标签:
园
center (a,b)
(1)(x-a)^2 + (y-b)^2 = R^2
(2)直线 y = kx +b;
(2)带入(1)得到2元1次多项式
ax^2 + bx + c = 0;
求dlt = b^2 - 4ac;
x = -b/2a +- sqrtl(dlt)
代入(2) 求y
static Pointf _CalculateCenter(Point p1, Point p2, Point p3)
{
Pointf ptCenter = {0.0};
// P1 -- P2 -- P3
//P1P2
float k1 = float(p2.y - p1.y) / float(p2.x - p1.x);
// center point of P1P2
float cx1 = ((float)p1.x + (float)p2.x) / 2;
float cy1 = ((float)p1.y + (float)p2.y) / 2;
//P1P2 perpendicular bisector
float ck1 = -1 / k1;
float cb1 = cy1 - ck1 * cx1;
//P2P3
float k2 = float(p3.y - p2.y) / float(p3.x - p2.x);
// center point of P1P2
float cx2 = ((float)p2.x + (float)p3.x) / 2;
float cy2 = ((float)p2.y + (float)p3.y) / 2;
//P2P3 perpendicular bisector
float ck2 = -1 / k2;
float cb2 = cy2 - ck2 * cx2;
ptCenter.x = (cb1 - cb2) / (ck2 - ck1);
ptCenter.y = ck1 * (cb1 - cb2) / (ck2 - ck1) + cb1;
return ptCenter;
}
标签:
原文地址:http://www.cnblogs.com/zhoug2020/p/5794304.html