I rotate points around a center point in 2D space. The points are the center point, the old mouse position and the new mouse position. My rotation function works fine, and I can calculate the angle perfectly. But I want to calculate a negative angle if the user moves his mouse in a direction that should be interpreted as counterclockwise.
For example, moving the mouse to the right (positive x axis) should rotate clockwise if you are above (less than) the y value of the center point, but it should rotate counterclockwise if you are actually lower (more) the y value of the center point.
Here is what I have:
PointF centerPoint;
PointF oldPoint;
PointF newPoint;
double Xc = centerPoint.X;
double Yc = centerPoint.Y;
double Xb = oldPoint.X;
double Yb = oldPoint.Y;
double Xa = newPoint.X;
double Ya = newPoint.Y;
double c2 = (Math.Pow(Xb - Xa, 2) + Math.Pow(Yb - Ya, 2));
double a2 = (Math.Pow(Xb - Xc, 2) + Math.Pow(Yb - Yc, 2));
double b2 = (Math.Pow(Xa - Xc, 2) + Math.Pow(Ya - Yc, 2));
double a = Math.Sqrt(a2);
double b = Math.Sqrt(b2);
double val = (a2 + b2 - c2) / (2 * a * b);
double angle = Math.Acos(val);
, , , , , .