Artificial intelligence 需要帮助解释弹丸运动的公式吗

Artificial intelligence 需要帮助解释弹丸运动的公式吗,artificial-intelligence,physics,game-physics,Artificial Intelligence,Physics,Game Physics,我需要实现一点人工智能来弄清楚如何用投射物的运动击中目标 我在维基百科上找到了这个: 这看起来正是我所需要的,特别是因为我有一个额外的问题,从零度以上的高度发射弹丸。然而,我的数学技能不太好,所以在我看来,这一切都是胡说八道,我不知道如何将它们翻译成代码 如果有人能用基本运算符(+-*%)和函数(sin、cos、sqrt等)将其分解成我能理解的东西,我会非常感激 公式很简单,不用担心推导过程 x is the horizontal distance away of the target you

我需要实现一点人工智能来弄清楚如何用投射物的运动击中目标

我在维基百科上找到了这个:

这看起来正是我所需要的,特别是因为我有一个额外的问题,从零度以上的高度发射弹丸。然而,我的数学技能不太好,所以在我看来,这一切都是胡说八道,我不知道如何将它们翻译成代码


如果有人能用基本运算符(+-*%)和函数(sin、cos、sqrt等)将其分解成我能理解的东西,我会非常感激

公式很简单,不用担心推导过程

x is the horizontal distance away of the target you're trying to hit
y is the vertical distance away of the target you're trying to hit
v is the initial velocity of the launch
g is the acceleration due to gravity (9.81 m/s on earth)

如果
xTarget/yTarget
是目标的位置,
xProj/yProj
是弹丸的初始位置,
v
是弹丸的初始速度(以米每秒为单位),然后,公式将转换为以下伪代码:

x = xTarget - xProj;
y = yTarget - yProj;
g = 9.8;

tmp = pow(v, 4) - g * (g * pow(x, 2) + 2 * y * pow(v, 2));

if tmp < 0
   // no solution
else if x == 0
   angle1 = pi/2;
   if y < 0
      angle2 = -pi/2;
   else
      angle2 = pi/2;
   end
else
   angle1 = atan((pow(v, 2) + sqrt(tmp)) / (g * x));
   angle2 = atan((pow(v, 2) - sqrt(tmp)) / (g * x));
end

我想你漏掉了你的阿坦。另外,要注意x=0(目标就在你的正上方?)。。。除以零。
if tmp < 0
   // no solution
else
   angle1 = atan2(pow(v, 2) + sqrt(tmp), g * x);
   angle2 = atan2(pow(v, 2) - sqrt(tmp), g * x);
end