c++ - Calculating the angle between Points -
working c++ , opencv
i trying calculate angle between 2 points.....i have 2d plane changing center point of bounding box, if center point in frame 1 has changed location in frame 2 need find angle of these 2 points.
here example of trying do:
can suggest way of working out.......? kind of mathematical solution or perhaps c++ function.
use dot product:
v1.v2 = v1.x * v2.x + v1.y * v2.y v1.v2 = |v1| * |v2| * cos(theta) ---------------------------------+ | +--> theta = acos(v1.v2 / |v1|*|v2|)
a sample code is:
float anglebetween(const point &v1, const point &v2) { float len1 = sqrt(v1.x * v1.x + v1.y * v1.y); float len2 = sqrt(v2.x * v2.x + v2.y * v2.y); float dot = v1.x * v2.x + v1.y * v2.y; float = dot / (len1 * len2); if (a >= 1.0) return 0.0; else if (a <= -1.0) return pi; else return acos(a); // 0..pi }
it calculates angle between v1 , v2 below image
Comments
Post a Comment