|
|
@ -186,24 +186,28 @@ icvRotatingCalipers( CvPoint2D32f* points, int n, int mode, float* out ) |
|
|
|
|
|
|
|
|
|
|
|
/* compute cosine of angle between calipers side and polygon edge */ |
|
|
|
/* compute cosine of angle between calipers side and polygon edge */ |
|
|
|
/* dp - dot product */ |
|
|
|
/* dp - dot product */ |
|
|
|
float dp0 = base_a * vect[seq[0]].x + base_b * vect[seq[0]].y; |
|
|
|
float dp[4] = { |
|
|
|
float dp1 = -base_b * vect[seq[1]].x + base_a * vect[seq[1]].y; |
|
|
|
+base_a * vect[seq[0]].x + base_b * vect[seq[0]].y, |
|
|
|
float dp2 = -base_a * vect[seq[2]].x - base_b * vect[seq[2]].y; |
|
|
|
-base_b * vect[seq[1]].x + base_a * vect[seq[1]].y, |
|
|
|
float dp3 = base_b * vect[seq[3]].x - base_a * vect[seq[3]].y; |
|
|
|
-base_a * vect[seq[2]].x - base_b * vect[seq[2]].y, |
|
|
|
|
|
|
|
+base_b * vect[seq[3]].x - base_a * vect[seq[3]].y, |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
float cosalpha = dp0 * inv_vect_length[seq[0]]; |
|
|
|
float maxcos = dp[0] * inv_vect_length[seq[0]]; |
|
|
|
float maxcos = cosalpha; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* number of calipers edges, that has minimal angle with edge */ |
|
|
|
/* number of calipers edges, that has minimal angle with edge */ |
|
|
|
int main_element = 0; |
|
|
|
int main_element = 0; |
|
|
|
|
|
|
|
|
|
|
|
/* choose minimal angle */ |
|
|
|
/* choose minimal angle */ |
|
|
|
cosalpha = dp1 * inv_vect_length[seq[1]]; |
|
|
|
for ( i = 1; i < 4; ++i ) |
|
|
|
maxcos = (cosalpha > maxcos) ? (main_element = 1, cosalpha) : maxcos; |
|
|
|
{ |
|
|
|
cosalpha = dp2 * inv_vect_length[seq[2]]; |
|
|
|
float cosalpha = dp[i] * inv_vect_length[seq[i]]; |
|
|
|
maxcos = (cosalpha > maxcos) ? (main_element = 2, cosalpha) : maxcos; |
|
|
|
if (cosalpha > maxcos) |
|
|
|
cosalpha = dp3 * inv_vect_length[seq[3]]; |
|
|
|
{ |
|
|
|
maxcos = (cosalpha > maxcos) ? (main_element = 3, cosalpha) : maxcos; |
|
|
|
main_element = i; |
|
|
|
|
|
|
|
maxcos = cosalpha; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/*rotate calipers*/ |
|
|
|
/*rotate calipers*/ |
|
|
|
{ |
|
|
|
{ |
|
|
|