Math : Transformations – rotating points (shapes, pixels, etc.)

Basic math often eludes me.  I was working on a graph and realized I didn’t remember how to rotate something outside 90° chunks.

radians = degrees * (pi/180)

To rotate a set of points in 2d.   Move the group of points so their center is at the origin (0,0).   Keep track of how much you adjusted the x and y coords to move the shape back once you have rotated it, then adjust the X,Y for each point:

new x = x * cos(radians) – y * sin(radians)
new y = y * cos(radians) + x * sin (radians)

add the x and y shift the point wasmoved . If you want to rotate clockwise inverse the angle or flip the operations +,- for new x and y

Leave a Reply

Your email address will not be published.