如何围绕任意点旋转一组二维形状
我正在制作一个身体"类,它将一堆 2D 形状组合在一起以形成一个可移动、可旋转的身体.
and i'm making a 'Body' class which holds a bunch of 2D shapes together to form a single moveable, rotatable body.
我需要知道的是如何旋转每个单独的形状,使其看起来像整个身体在旋转,而不是每个形状都围绕它的中心进行自己的旋转.我不能只是将每个形状的旋转中心更改为同一点,因为这也会导致它们的位置受到影响.
What i need to know is how i can rotate each individual shape in a way that makes it look like the whole body is rotating, not each shape doing it's own rotation around it's center. I can't just change each shapes center of rotation to the same point, as this would cause their placement to be affected also.
因此,我需要找到某种方程式,使用 body center 重新定位和重新旋转身体中的每个单独形状,以保持身体形状不变形?
Therefore i need to find some kind of equation that uses the bodies center to re-position and re-rotate each individual shape in a body in a way that keeps the Body figure undeformed?
我该怎么做?
推荐答案
任意点旋转的方法是先减去点坐标,绕原点旋转,再加上点坐标.
The way to rotate by an arbitrary point is first substract the point coordinates, do the rotation about the origin and then add the point coordinates.
x2 = px + (x1-px)*cos(q)-(y1-py)*sin(q)
y2 = py + (x1-px)*sin(q)+(y1-py)*cos(q)
其中px,py
是旋转点坐标,x1,y1
是原始2D形状顶点,x2,y2
是旋转坐标, 和 q
以弧度为单位的角度.
where px, py
are the rotation point coordinates, and x1,y1
the original 2D shape vertex and x2,y2
the rotated coordinates, and q
the angle in radians.
相关文章