Hi,
You can find the bounds of the rotated box using the rotateRect method shown below.
POINT rotatePointAt(POINT point, POINT pivot, float angle)
{
if (angle > -0.00001f && angle < 0.00001f)
return point;
point.x -= pivot.x;
point.y -= pivot.y;
float rad = angle * M_PI / 180;
POINT res = {
point.x * cos(rad) - point.y * sin(rad),
point.x * sin(rad) + point.y * cos(rad)
};
res.x += pivot.x;
res.y += pivot.y;
return res;
}
void rotatePointsAt(POINT* points, int count, POINT pivot, float angle)
{
if (angle > -0.00001f && angle < 0.00001f)
return;
for (int i = 0; i < count; ++i)
points[i] = rotatePointAt(points[i], pivot, angle);
}
RECT rotateRectAt(const RECT& rc, POINT pivot, float angle)
{
if (angle > -0.00001f && angle < 0.00001f)
return rc;
POINT p[] = {
{ rc.left, rc.top },
{ rc.right, rc.top },
{ rc.right, rc.bottom },
{ rc.left, rc.bottom }
};
rotatePointsAt(p, 4, pivot, angle);
float minX = min(p[0].x, min(p[1].x, min(p[2].x, p[3].x)));
float minY = min(p[0].y, min(p[1].y, min(p[2].y, p[3].y)));
float maxX = max(p[0].x, max(p[1].x, max(p[2].x, p[3].x)));
float maxY = max(p[0].y, max(p[1].y, max(p[2].y, p[3].y)));
RECT res = { minX, minY, maxX, maxY };
return res;
}
Stoyan