Drawing a Rotated Rectangle

后端 未结 6 793
情歌与酒
情歌与酒 2020-12-06 17:43

I realize this might be more of a math problem.

To draw the lines for my rectangles I need to solve for their corners. I have a rectangle center at (x,y) With a def

6条回答
  •  旧巷少年郎
    2020-12-06 18:10

    If 'theta' is the anti-clockwise angle of rotation, then the rotation matrix is:

    | cos(theta)  -sin(theta) |
    | sin(theta)   cos(theta) |
    

    i.e.

    x' = x.cos(theta) - y.sin(theta)
    y' = x.sin(theta) + y.cos(theta)
    

    If the rotation point isn't at the origin, subtract the center of rotation from your original coordinates, perform the rotation as shown above, and then add the center of rotation back in again.

    There's examples of other transformations at http://en.wikipedia.org/wiki/Transformation_matrix

提交回复
热议问题