三维空间点至拟合直线距离

孤街浪徒 提交于 2019-11-27 12:43:27
cv::Vec6d fitting_line;
int distType = cv::DIST_L2; // 距离类型  
double param = 0; // 距离参数  
double reps = 1e-2; // 径向的精度参数  
double aeps = 1e-2; // 角度精度参数  

fitLine(Points, fitting_line, distType, param, reps, aeps);
double DistanceOfPointToLine(cv::Point3f s, cv::Vec6d fitting_line)
{
	cv::Point3f a = cv::Point3f(fitting_line[3], fitting_line[4], fitting_line[5]);
	cv::Point3f b = cv::Point3f(fitting_line[3] + fitting_line[0], fitting_line[4] + fitting_line[1], fitting_line[5] + fitting_line[2]);
	double ab = sqrt(pow((a.x - b.x), 2.0) + pow((a.y - b.y), 2.0) + pow((a.z - b.z), 2.0));
	double as = sqrt(pow((a.x - s.x), 2.0) + pow((a.y - s.y), 2.0) + pow((a.z - s.z), 2.0));
	double bs = sqrt(pow((s.x - b.x), 2.0) + pow((s.y - b.y), 2.0) + pow((s.z - b.z), 2.0));
	double cos_A = (pow(as, 2.0) + pow(ab, 2.0) - pow(bs, 2.0)) / (2 * ab*as);
	double sin_A = sqrt(1 - pow(cos_A, 2.0));
	return as*sin_A;
}

参考:

https://blog.csdn.net/piaoxuezhong/article/details/71519426

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!