Rotate line around center

半城伤御伤魂 提交于 2019-12-12 03:35:49

问题


I have to use a propriertary graphics-engine for drawing a line. I can rotate the whole drawing by its origin point (P1). What I want, is to rotate it around its center point(M). So basically that it looks like L_correct instead of L_wrong.

I think, it should be possible to correct it, by moving it from P1 to P2. But I cannot figure out what formula could be used, to determine the distance. It must probably involve the angle, width and height...

So basically my question is, if there is a function to determine x2 and y2 based on my available data?


回答1:


Let's assume you have a primitive method that rotates a drawing by any given angle phi. What you want is to use that primitive to rotate a drawing D around a point M instead. Here is a sketch of how to proceed.

  1. Translate you drawing by -M, i.e., apply the transformation T(P) = P - M to all points P in your drawing. Let T(D) be the translation of D.

  2. Now use the primitive to rotate T(D) by the desired angle phi. Let R(T(D)) be the result.

  3. Now translate the previous result by M and get the rotated drawing. In other words, use the transformation T'(P) = P + M.

Note that in step 1 above M is mapped to the origin 0, where the rotation primitive is known to work. After rotating in step 2, the opposite translation of step 3 puts back the drawing on its original location as this time 0 is mapped to M.



来源:https://stackoverflow.com/questions/35442860/rotate-line-around-center

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!