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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:27:26+00:00 2026-05-14T00:27:26+00:00

I have a point in a rectangle that I need to rotate an arbitrary

  • 0

I have a point in a rectangle that I need to rotate an arbitrary degree and find the x y of the point. How can I do this using javascript.

Below the x,y would be something like 1,3 and after I pass 90 into the method it will return 3,1.

|-------------|
|  *          |
|             |
|             |
|-------------|
 _____
|    *|
|     |
|     |
|     |
|     |
 _____

|-------------|
|             |
|             |
|            *|
|-------------|
 _____
|     |
|     |
|     |
|     |
|*    |
 _____

Basically I am looking for the guts to this method

function Rotate(pointX,pointY,rectWidth,rectHeight,angle){
   /*magic*/    
   return {newX:x,newY:y};
}
  • 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-14T00:27:27+00:00Added an answer on May 14, 2026 at 12:27 am

    This should do it:

    function Rotate(pointX, pointY, rectWidth, rectHeight, angle) {
      // convert angle to radians
      angle = angle * Math.PI / 180.0
      // calculate center of rectangle
      var centerX = rectWidth / 2.0;
      var centerY = rectHeight / 2.0;
      // get coordinates relative to center
      var dx = pointX - centerX;
      var dy = pointY - centerY;
      // calculate angle and distance
      var a = Math.atan2(dy, dx);
      var dist = Math.sqrt(dx * dx + dy * dy);
      // calculate new angle
      var a2 = a + angle;
      // calculate new coordinates
      var dx2 = Math.cos(a2) * dist;
      var dy2 = Math.sin(a2) * dist;
      // return coordinates relative to top left corner
      return { newX: dx2 + centerX, newY: dy2 + centerY };
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code: public class Area { Texture2D point; Rectangle rect; SpriteBatch _sB;
i have bug that i cannot find, i have Class Point with method who
I have a need to define a polygon that would be the legal area,
I'm learning to code in Java. I have this assessment that I need to
I have the following paint event (form) that is drawing the rectangle: void LogicSimulationViewerForm_Paint(object
I have one line (two point (x,y) (x1,y1)) and a rectangle with focus point
I need to use IBM Informix for my project where I have point coordinates
I'm pretty confused. I have a point: x= -12669114.702301 y= 5561132.6760608 That I got
The code below shows a rectangle class using double points, which are also stored
I currently have a vertical slider that is controlled by the user using startDrag.

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.