Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rotate rectangle around a point

How would I get 4 points rotated a certain degrees around a pointer to form a rectangle? I can rotate a point around a point, but I can't offset it to make a rectangle that isn't distorted.

like image 231
Anonymous Avatar asked Dec 16 '10 22:12

Anonymous


People also ask

How do you rotate around a specific point?

Precisely speaking: A rotation of about a given point takes each point on a shape and moves it to such that is on the circle with center and radius O P ¯ and. Informally: To rotate a shape, move each point on the shape the given number of degrees around a circle centered on the point of rotation.

What does it mean to rotate around a point?

To rotate a shape or object means to spin it around a specific point (center), without moving it in any other way. Rotation does not affect size or shape.


1 Answers

If you can rotate a point around a point then it should be easy to rotate a rectangle - you just rotate 4 points.

Here is a js function to rotate a point around an origin:

function rotate_point(pointX, pointY, originX, originY, angle) {
    angle = angle * Math.PI / 180.0;
    return {
        x: Math.cos(angle) * (pointX-originX) - Math.sin(angle) * (pointY-originY) + originX,
        y: Math.sin(angle) * (pointX-originX) + Math.cos(angle) * (pointY-originY) + originY
    };
}

And then you can do this to each point. Here is an example: http://jsfiddle.net/dahousecat/4TtvU/

Change the angle and hit run to see the result...

like image 146
Felix Eve Avatar answered Sep 18 '22 01:09

Felix Eve