绕中心旋转线 [英] Rotate line around center
问题描述
我必须使用专有的图形引擎来绘制线条.我可以通过其原点 (P1) 旋转整个图形.我想要的是围绕其中心点(M)旋转它.所以基本上它看起来像 L_correct 而不是 L_wrong.
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.
我认为,应该可以通过将其从 P1 移到 P2 来纠正它.但我无法弄清楚可以使用什么公式来确定距离.大概一定涉及到角度、宽度、高度……
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...
所以基本上我的问题是,是否有一个函数可以根据我的可用数据确定 x2 和 y2?
So basically my question is, if there is a function to determine x2 and y2 based on my available data?
推荐答案
假设您有一个原始方法,可以将绘图旋转任意给定角度 phi
.您想要的是使用该图元围绕点 M
旋转绘图 D
.这是如何进行的草图.
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.
通过
-M
翻译你的画,即,将变换T(P) = P - M
应用于所有点P
> 在你的画中.让T(D)
成为D
的翻译.
Translate you drawing by
-M
, i.e., apply the transformationT(P) = P - M
to all pointsP
in your drawing. LetT(D)
be the translation ofD
.
现在使用图元将 T(D)
旋转所需的角度 phi
.让 R(T(D))
成为结果.
Now use the primitive to rotate T(D)
by the desired angle phi
. Let R(T(D))
be the result.
现在用M
翻译之前的结果,得到旋转后的图.换句话说,使用转换T'(P) = P + M
.
Now translate the previous result by M
and get the rotated drawing. In other words, use the transformation T'(P) = P + M
.
请注意,在上面的步骤 1 中,M
被映射到原点 0
,已知旋转原语在此处工作.在第 2 步旋转后,第 3 步的相反平移将图形放回其原始位置,因为这次 0
映射到 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
.
这篇关于绕中心旋转线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!