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
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
I see what you mean however I was hoping to be able to calculate the new x/y based only on the old x/y and the rotation. There are only 4 possible rotations for each of the shapes so I could just manually input them all but I wanted a cleaner way to do it.
Basically, given only the first set of coords and a rotation of 90 degrees I want to be able to calculate the new set of coords.
My math is only slightely worse than my ability to explain my problems, sorry. ![]()
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
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
North America
Europe, Middle East and Africa
Asia Pacific