When you rotate a point (X, Y) around the origin through angle theta, the point's new coordinates (X', Y') are given by:
X' = Cos(theta) * X - Sin(theta) * Y
Y' = Sin(theta) * X + Cos(theta) * Y
To rotate around a point other than the origin, translate the point so the point of rotation is at the origin, rotate, and then translate back.
This example starts with a square centers at the origin. For several angles, the program rotates the square's points, translates to center the square on the form, and draws the rotated/translated square.
|