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 5960977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:54:02+00:00 2026-05-22T18:54:02+00:00

I think I am just over-complicating this but I have a rectangle that I

  • 0

I think I am just over-complicating this but I have a rectangle that I am trying to draw using a rotation value. I have the coordinates of all four vertices and I need the new coordinates when rotated by X degrees clockwise.

EDIT: One thing to note, I am drawing on the HTML5 canvas so the coordinate system is a little different. X and Y are always > 0 and and increase in Y progresses downward.

Any ideas?

Thanks

  • 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-05-22T18:54:03+00:00Added an answer on May 22, 2026 at 6:54 pm

    So all you really need is a function that takes a point, an origin (the center of your rectangle in this case) and an angle:

    function rotatePoint(p, origin, angle) {
      if (angle === 0) return p;
      // make the origin essentially zero:
      var px = p.x - origin.x;
      var py = p.y - origin.y;
      if (px == 0 && py == 0) return p;
      var rad = angle * Math.PI / 180;
      var cosine = Math.cos(rad);
      var sine = Math.sin(rad);
      p.x = cosine * px - sine * py;
      p.y = sine * px + cosine * py;
      // put the point back:
      p.x += origin.x;
      p.y += origin.y;
      return p;
    };
    

    So if you wanted to rotate a vertex at 10,10 by 45 deggrees about the center which is (say) 20,20, you would do: rotatePoint({x:10, y:10}, {x:20, y:20}, 45) would give you (20, 5.85), and so on.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay, I think I might be over-complicating this issue but I truly am stuck.
I think this is just a Best Practices question, but I was wondering if
I have just switched over from the old png transparency fix using a htc
Im sure this is another time I'm over complicating things, or just making myself
I have an app that retrieves data over httpconnection just b calling a php
just think that when I opened my file then when I want to write
I'm not very used to programming with flags, but I think I just found
I think I'm just missing something simple here but here is what I am
[see later answer for more] I think this is just a simple rails question,
Okay, I think I'm just making a stupid mistake here, but I want to

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.