Opencv---三点拟合圆

2DAPoint getFitCircle(_2DAPoint pt1, _2DAPoint pt2, _2DAPoint pt3, double *_radius)
{ 
	_2DAPoint point;
	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) < 1e-5)
	{ 
		*_radius = -1;
		return point;
	}

	double x0 = -(d * e - b * f) / det;
	double y0 = -(a * f - c * e) / det;
	*_radius = hypot(x1 - x0, y1 - y0);
	point.x = x0;
	point.y = y0;
	return point;
}
    原文作者:VS,路在脚下
    原文地址: https://blog.csdn.net/u013345672/article/details/119577901
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞