根据角度、速度和起始位置计算位置

Calculate a position based on an angle a speed and a starting position

尽管我在网上阅读了很多关于它的文章,但我无法解决我的问题。

有一个二维平面图,其中 x, y 是屏幕的左上角。 我有一个点,从中我知道位置 x、y、方向(0 到 360 度)和速度(以每步像素为单位)。

根据我所读到的,如果我想在一步之后计算点的下一个位置,我使用以下代码:

  self.px.X := round(self.px.X + self.speed * cos(direction));
  self.px.Y := round(self.px.Y + Self.speed * sin(direction));

出于测试目的,我使用速度值 10 和方向值 90。 正常情况下,该点应该水平移动(甚至垂直移动也是一个进步),但它是在对角线移动,甚至不是 45°。

有人知道我做错了什么吗?

正如 Andreas Rejbrand 所说(但我不知道如何将评论变成答案,抱歉 Andreas),解决方案是通过简单地调用 degToRad 函数来使用弧度数:

self.px.X := round(self.px.X + self.speed * cos(DegToRad(direction)));
self.px.Y := round(self.px.Y + Self.speed * sin(DegToRad(direction)));