I am trying to rotate a rectangle using the matrix (x cos θ – y sin θ, x sin θ + y cos θ). The problem is that the rectangle is getting smal and reaching the origin point per time (I am using timer). Here is my code.
void WINAPI Rotate(POINT arr[5])
{
static POINT origin = { 400, 400 };
static int i;
static const double angle = 0.1;
for (i = 0; i < 5; ++i)
{
// translate
arr[i].x -= origin.x;
arr[i].y -= origin.y;
// rotate
arr[i].x = arr[i].x * cos(angle) - arr[i].y * sin(angle);
arr[i].y = arr[i].x * sin(angle) + arr[i].y * cos(angle);
// translate
arr[i].x += origin.x;
arr[i].y += origin.y;
}
}
So I want the points in arr to be fixed distance from the origin point after rotation. I don’t want them to reach the origin point per time.
Initially:
arr[0].x = 200;
arr[0].y = 100;
arr[1].x = 100;
arr[1].y = 100;
arr[2].x = 100;
arr[2].y = 200;
arr[3].x = 200;
arr[3].y = 200;
arr[4].x = arr[0].x;
arr[4].y = arr[0].y;
If this is the wrong way for rotation, does someone know a correct method to rotate a rectangle about its origin, without affecting its size?
Here are snapshots while it rotates:

In your rotation,
you use the new
x-coordinate to compute the newy-coordinate, but you should use the old one. To fix it, use a temporary,