一杯清酒邀明月
天下本无事,庸人扰之而烦耳。

求两点间距离

1 /***** 求两点间距离*****/
2 float getDistance(CvPoint pointO, CvPoint pointA)
3 {
4     float distance;
5     distance = powf((pointO.x - pointA.x), 2) + powf((pointO.y - pointA.y), 2);
6     distance = sqrtf(distance);
7     return distance;
8 }

点到直线的距离:P到AB的距离

 1 /***** 点到直线的距离:P到AB的距离*****/
 2 //P为线外一点,AB为线段两个端点
 3 float getDist_P2L(CvPoint pointP, CvPoint pointA, CvPoint pointB)
 4 {
 5     //求直线方程
 6     int A = 0, B = 0, C = 0;
 7     A = pointA.y - pointB.y;
 8     B = pointB.x - pointA.x;
 9     C = pointA.x*pointB.y - pointA.y*pointB.x;
10     //代入点到直线距离公式
11     float distance = 0;
12     distance = ((float)abs(A*pointP.x + B*pointP.y + C)) / ((float)sqrtf(A*A + B*B));
13     return distance;
14 }

 

posted on 2022-02-25 14:38  一杯清酒邀明月  阅读(2111)  评论(0编辑  收藏  举报