Does anyone know how I can rotate a point around another in OpenCV?
I am looking for a function like this:
Point2f rotatePoint(Point2f p1, Point2f center, float angle)
{
/* MAGIC */
}
These are the steps needed to rotate a point around another point by an angle alpha:
The standard equation for rotation is:
x' = xcos(alpha) - ysin(alpha)
y' = xsin(alpha) + ycos(alpha)
Let's take the example of Point(15,5) around Point(2,2) by 45 degrees.
Firstly, translate:
v = (15,5) - (2,2) = (13,3)
Now rotate by 45°:
v = (13*cos 45° - 3*sin 45°, 13*sin 45° + 3*cos 45°) = (7.07.., 11.31..)
And finally, translate back:
v = v + (2,2) = (9.07.., 13.31..)
Note: Angles must be specified in radians, so multiply the number of degrees by Pi / 180