Is this how rotation about a point is done?

后端 未结 4 1956
醉酒成梦
醉酒成梦 2020-12-20 10:11

Let\'s say I have a polygon with points:

(0,0)
(100,0)
(100,100)
(0,100)

Lets also let it\'s center be (50,50).

To rotate it would

4条回答
  •  离开以前
    2020-12-20 10:51

    You first have to translate (50, 50) to the origin, perform the rotation, and then translate the origin back to (50, 50).

    More specifically, given matrices A, B, where A translates the center of rotation to the origin and usually takes the form:

        |1  0  Sx|
    A = |0  1  Sy|
        |0  0  1 |

    And B is your rotation matrix:

        |cos θ -sin θ 0|
    B = |sin θ  cos θ 0|
        | 0      0    1|

    Then the acutal transformation you need for a vector p = x py 1> rotated about a point (Sx, Sy) by an angle θ is given by p' = ABA-1pT. The extra dimension is needed in the matrices A and B and the vector p to account for the fact that since matrix multiplication is just a linear transformation, it results in the origin always being mapped to the origin. That means that we can't really do translation; the trick is to add an extra dimension and ensure that all transformations are on vectors away from the origin.

    As Jason S. suggest, additional information can be found at Wikipedia's entry on Affine Transformations or Wolfram's entry on the same subject.

提交回复
热议问题