# ActionScript 3

Currently Being Moderated

## Rotating points around a start coordinate

### May 2, 2012 8:54 AM

I am playing around with coding a shape fitting game (similar to Tetris). I have a bunch of shapes that are stored as coordinates relative to a start point ({0,0})so an 'L' shape would be {0,1}, {0,2},{1,2}. Is there a simple way that I can calculate the new coordinates that describe the shape after it has been rotated 90 degrees in either direction?

To clarify, a rotation of 90deg clockwise would result in {0,0}, {-1,0},{-2,0}, {-2,1}.

I would like to do this as simply as possible as I am trying to be processor friendly and was thinking that as I am only interested in rotations of 90degree intervals that there might some clever cheat I could use.

I have asked on a few math forums but I get answers about matrices full of math notation that I don't understand. I might be able to do the math but I would like an explanation from a coder rather than a mathmatician if possible

Cheers all

Replies
• Currently Being Moderated

I'm a mathematician but I did notice a patter with the one example you gave

for each point swap the x, yand negate the new x

so

newX = -oldY

newY = oldX

it might not work generally I was just going off the example you gave me, if it doesn't and you don't get any responses I'll get back to you with a solution tomorrow, I should be able to reduce the matrices to simple operations

|
Mark as:
• Currently Being Moderated

you cna't base the new x just on the old x and the new y on the old y. inherently the new x depends on the old y

\begin{align} x'&=x\cos\theta-y\sin\theta\\ y'&=x\sin\theta+y\cos\theta. \end{align}

now cos(90) = 0 and sin(90) = 1

so for rotation of 90

x' = -y

y' = x

now cos(180) = -1 and sin(180) = 0

so for rotation 180

x' = -x

y' = -y

now cos(270) = 0 and sin(90) = -1

so for rotation 270

x' = y

y' = -x

|
Mark as:
Actions

#### More Like This

• Retrieving data ...

#### Answers + Points = Status

• 10 points awarded for Correct Answers