如何计算旋转形状 AS3 中点的位置
我正在创建一个游戏,在其中我通过围绕圆的半径创建点来绘制一系列多边形。
后来我旋转形状,我需要根据旋转计算点的新位置(X,Y)。我有每个点的旧 XY、形状中心的 XY、形状半径和旋转。
看看我的问题图。
I am creating a game in which I draw a series of polygons by creating points around a radius of a cricle.
Later on I rotate the shapes and I need to calculate the new location (X,Y) of the points based on the rotation. I have the Old XY of each point, the XY of the center of the shape, radius of shape and the rotation.
Have a look at my diagram of the problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
应该可以使用矩阵变换来实现此目的,但您也可以手动执行此操作:
http://www.siggraph.org/education/materials/HyperGraph /modeling/mod_tran/2drota.htm
所以本质上是;
这假设初始X/Y是相对于旋转中心的,因此您必须在开始之前减去中心点,然后在计算后再次添加它以正确放置它。
希望这有帮助!
It should be possible to use matrix transformations for this, but you can also do it manually:
http://www.siggraph.org/education/materials/HyperGraph/modeling/mod_tran/2drota.htm
So essentially;
This assumes that the initialX/Y is relative to the center of rotation, so you would have to subtract the center point before starting, and then add it again after the calculation to place it correctly.
Hope this helps!
对于每个点:
原始 [x,y] 和新 [newX,newY] 坐标均相对于旋转中心。如果原始 [x,y] 是绝对值,则必须首先计算相对值:
如果 x=0,请确保 arctan2 函数提供 PI/2 或 -PI/2 的结果。原始反正切函数不允许 x=0。
For each point do:
Original [x,y] and new [newX,newY] coordinates are both relative to the center of your rotation. If your original [x,y] is absolut, you have to calculate relative first:
Make sure your arctan2 function provides a result of PI/2 or -PI/2 if x=0. Primitive arctan functions do not allow x=0.