求两点间距离
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 }