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/qq_36638362/article/details/99674541