您拥有运动的角度和长度(即斜边),因此您应该能够使用 sin 或 cos 来计算所需的 x 和 y 运动量。
Use trigonometry.
You have the angle and the length of movement (which is your hypotenuse) so you should be able to use sin or cos to calculate the amount of x and y movement required.
double radians = (Math.PI/180)*angleInDegrees;
x += speed * Math.Cos(radians);
y += speed * Math.Sin(radians);
正如其他海报所提到的,这是基于使用三角学将旋转应用于速度矢量(在本例中,0 度矢量指向右侧) )。
Just to clarify, since this is C#, you'd want to do this
double radians = (Math.PI/180)*angleInDegrees;
x += speed * Math.Cos(radians);
y += speed * Math.Sin(radians);
As other posters have mentioned, this is based on using trigonometry to apply a rotation to a speed vector (in this case, the 0 degrees vector is pointing to the right).
发布评论
评论(4)
不能 100% 确定这就是您想要的,但我认为您想做:
其中
angle
是对象的旋转,x
和y< /code> 是它的坐标。
speed
是物体的速度。Not 100% sure that this is what you want, but I think you want to do:
Where
angle
is the rotation of your object, andx
andy
are its coordinates.speed
is the speed of your object.但这取决于你的旋转方向。此代码适用于向上(北)0 度的旋转,顺时针移动。
But it depends on the orientation of your rotation. This code will work for rotation orientated up (north) at 0 degrees, moving clock-wise.
使用三角学。
您拥有运动的角度和长度(即斜边),因此您应该能够使用 sin 或 cos 来计算所需的 x 和 y 运动量。
Use trigonometry.
You have the angle and the length of movement (which is your hypotenuse) so you should be able to use sin or cos to calculate the amount of x and y movement required.
只是为了澄清,因为这是 C#,所以您需要这样做
正如其他海报所提到的,这是基于使用三角学将旋转应用于速度矢量(在本例中,0 度矢量指向右侧) )。
Just to clarify, since this is C#, you'd want to do this
As other posters have mentioned, this is based on using trigonometry to apply a rotation to a speed vector (in this case, the 0 degrees vector is pointing to the right).