Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8746913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:16:13+00:00 2026-06-13T12:16:13+00:00

I am trying to rotate a rectangle using the matrix (x cos θ –

  • 0

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:

enter image description here enter image description here enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T12:16:13+00:00Added an answer on June 13, 2026 at 12:16 pm

    In your rotation,

    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);
    

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

    double temp = arr[i].x * cos(angle) - arr[i].y * sin(angle);
    arr[i].y = arr[i].x * sin(angle) + arr[i].y * cos(angle);
    arr[i].x = temp;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to rotate a rectangle by rotating its points , using this code
I'm trying to rotate a bitmap 90 degrees using the following function. The problem
Ok I've been trying to rotate a Rectangle that sits on top of an
I'm trying to rotate and then scale an image using android.graphics.Matrix. The code is
I am trying to rotate an image in OpenCV. I've used this code that
I'm trying to rotate an SVG <polygon> (or any other element) using this: var
i'm unsuccessfully trying to rotate a rectangle around an external point while tweening. i'm
I am trying to use manipulation on a UI element (rectangle) and can rotate
I'm trying to rotate an array such that given a number and an array,
I'm trying to rotate a camera image. The code looks like that: Bitmap result

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.