如何围绕任意点旋转一组2D形状 [英] How to rotate a group of 2D shapes around an arbitrary point

查看:142
本文介绍了如何围绕任意点旋转一组2D形状的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个身体类,它持有一堆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?

如何做到这一点?

推荐答案

我假设你用笛卡尔坐标(x,y)表示点,并且你喜欢向量的基本概念。

I'll assume you're representing points in Cartesian coordinates (x,y) and that you're comfortable with the basic idea of vectors.

以给定角度θ旋转单个点;围绕原点(0,0),我们将其转换如下:

To rotate a single point by a given angle θ around the origin (0,0), we transform it like so:

x'= x cos(θ) - y sin(θ)

y'= x sin(θ)+ y cos(θ)

x' = x cos(θ) - y sin(θ)
y' = x sin(θ) + y cos(θ)

或以矢量矩阵形式:

X' = M (θ) X

X' = M(θ) X

要旋转 X 点点 B ,请执行以下操作:

To rotate the point X around a point B, do this:

X' = B M (<θ>)( X B

;关于其中心 B ,只需将每个形状的中心旋转θ约b b,并且围绕其自己的中心旋转每个形状θ, (您可以按任何顺序执行这些步骤)。

To rotate the whole Body by θ about its center B, just rotate each shape's center by θ about B, and rotate each shape about its own center by θ (you can do those steps in any order).

这篇关于如何围绕任意点旋转一组2D形状的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆