Say I have a rectangle (R) and inside said rectangle, I have two points, A and B. I need to rotate the rectangle around the center point (C) to the point A and B have equal y coordinates. Since the solution to this could produce two separate answers (where Ax is < Bx, and where Ax is > Bx), I would like to constrain this to only allow the solution where Ax < Bx.
My solution is to solve for theta when rotating around M (the midpoint between A and B) and then to rotate around C by theta (below).
Will this work in all cases/is this optimal? Thanks in advance!
CGPoint m = CGPointMake(a.x / 2 + b.x / 2, a.y / 2 + b.y / 2);
float dx = m.x - a.x;
float dy = m.y - a.y;
float radians = -atan2f(dy, dx)