Если повороты бывают только на 90 °, 180 ° или 270 ° с использованием Math.Sin()
и Cos()
излишне.
При поворотах на 90 ° координатами можно довольно легко манипулировать ...
W : Image width before rotation
H : Image height before rotation
x : X coordinate in image before rotation
x' : X coordinate in image after rotation
y : Y coordinate in image before rotation
y' : Y coordinate in image after rotation
For 0° CCW:
x' = x
y' = y
For 90° CCW:
x' = y
y' = W - x
For 180° CCW/CW:
x' = W - x
y' = H - y
For 270° CCW:
x' = H - y
y' = x
In C#:
public static PointF RotatePoint(float x, float y, int pageWidth, int pageHeight, int degrees)
{
switch(turns)
{
case 0: return new PointF(x,y);
case 90: return new PointF(y, pageWidth - x);
case 180: return new PointF(pageWidth - x, pageHeight - y);
case 270: return new PointF(pageHeight - y, x);
default:
// Either throw ArgumentException or implement the universal logic with Sin(), Cos()
}
}