Rotating points in a polygon

I am working on a game using Java2D, and I’m trying to rotate a bounding box surrounding a sprite.

The original points of the bounding box are just obtained from the size of the image used for the sprite, so I have a polygon with the points (0,0), (imgWidth,0),(imgWidth,imgHeight),(0,imgHeight)

Now, I’m trying to figure out how to rotate these points around any other given point (as each sprite may have a different rotation point) by a particular direction (in degrees at the moment) to find the new polygon which will define the bounding box.

Can anybody help me with the equations? Math is definitely my weak point, unfortunately .

This was just discussed over here:

http://www.java-gaming.org/cgi-bin/JGNetForums/YaBB.cgi?board=2D;action=display;num=1106239125

The precise formulas, however, can be found (with the explanation of how they are derived) in Chris Hargrove’s Demo News tutorials. The zip file is here:

http://glstation.free.fr/mine/djgpp/tutor/dntut.zip

(The DOC files inside are really text files, so don’t worry about having Word.)

The forumulas he gives are:

  NewX = (OldX*Cos(angle)) - (OldY*Sin(angle))
  NewY = (OldY*Cos(angle)) + (OldX*Sin(angle))

For those who read my Robotron 4096 code, those formulas should seem familiar. After all, they’re the same ones I used to rotate the 3D sprites into view. :slight_smile:

Brilliant, thanks, I’ll check this out :slight_smile: