|
QPointF tcircle(QPointF pt1, QPointF pt2, QPointF pt3, double &radius)
{
double x1 = pt1.x(), x2 = pt2.x(), x3 = pt3.x();
double y1 = pt1.y(), y2 = pt2.y(), y3 = pt3.y();
double a = x1 - x2;
double b = y1 - y2;
double c = x1 - x3;
double d = y1 - y3;
double e = ((x1 * x1 - x2 * x2) + (y1 * y1 - y2 * y2)) / 2.0;
double f = ((x1 * x1 - x3 * x3) + (y1 * y1 - y3 * y3)) / 2.0;
double det = b * c - a * d;
if( fabs(det)
{
radius = -1;
return QPointF(0,0);
}
double x0 = -(d * e - b * f) / det;
double y0 = -(a * f - c * e) / det;
radius = hypot(x1 - x0, y1 - y0);
return QPointF(x0, y0);
}
|
|