Rotate point in rectangle

Posted by Dested on Stack Overflow See other posts from Stack Overflow or by Dested
Published on 2010-03-12T12:10:50Z Indexed on 2010/03/12 12:17 UTC
Read the original article Hit count: 468

Filed under:
|
|
|

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

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about rotate