根据旋转角度计算XY移动? [英] Calculating X Y movement based on rotation angle?

查看:98
本文介绍了根据旋转角度计算XY移动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我在 2D 空间中有一个物体可以旋转,然后应该根据它的旋转角度移动.

Say I have an object in 2D space that can rotate and then should move according to its rotation angle.

例如:

  • 如果角度为 0(指向上方),则 on_timer 应该将 Y 移动 1,X 移动 0.

  • If angle is 0(pointing upwards), then on_timer it should move 1 by Y and 0 by X.

如果角度是 45,那么它应该移动 1 个 Y 和 1 个 X.

If angle is 45, then it should move 1 by Y and 1 by X.

如果指向 90 度,则 Y 为 0,X 为 1.

If pointing 90 degrees, then 0 by Y and 1 by X.

如果指向 135 度,则 Y 为 -1,X 为 +1,依此类推

If pointing 135 degrees, then -1 by Y and +1 by X, etc.

你知道计算这个的函数吗?

Do you know any functions for calculating this?

推荐答案

好吧,它似乎在不同角度以不同速度移动.

well, it seems to move at different speeds for different angles.

对于 0 度(直线向上),它移动了 1,但是 45 度它移动了 sqrt(1^2 + 1^2) = 1.41.

For 0 degress (straight up) it moved by 1, but 45 begrees it moved sqrt(1^2 + 1^2) = 1.41.

我想你想看看 Sin 和 Cos.

I think you want to look at Sin and Cos.

X += Speed * Math.Cos(angle);
Y += speed * Math.Sin(angle);

问候 Gert-Jan

Regards Gert-Jan

这篇关于根据旋转角度计算XY移动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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