0

这似乎是一个非常容易解决的问题,但我发现的一切都太复杂了,我无法理解。

我有这个基本的弹道方程:

弹道轨迹

鉴于我知道 v、g、x 和 y,我将如何找到 theta?在纸上很容易阅读,但我不知道如何在代码中完成。

[编辑#3:]我的尝试(从下面的答案输入)是这样的:

gx = g*x
brackets = gx^2 + 2*y*v^2
sqrroot = sqrt( v^4 - g*brackets )

top1 = v^2 + sqrroot
theta1 = atan( top1 / gx )

top2 = v^2 - sqrroot
theta2 = atan( top2 / gx )
4

5 回答 5

1

更像这样。

gx = g*x
brackets = g*x^2 + 2*y*v^2
sqrroot = sqrt( v^4 - g*brackets )
top1 = v^2 + sqrroot
theta1 = atan( top1 / gx )
top2 = v^2 - sqrroot
theta2 = atan( top2 / gx )

您必须考虑公式中的加号和减号。

您在乘法之前计算平方。在某些语言中,您可以通过计算 g*x*x 来计算 g*x^2。

于 2013-07-16T15:24:50.597 回答
1

你忽略了一个解决方案 - 你有

top = v^2 + sqrroot

但您还需要重新计算

top = v^2 - sqrroot

±在你的等式中解释。

所以:

top1 = v^2 + sqrroot
top2 = v^2 - sqrroot

theta1 = atan(top1 / gx)
theta2 = atan(top2 / gx)

(我不知道equation您的代码中有什么,但我假设您的意思是top

于 2013-07-16T15:21:56.303 回答
0

解决方案

#include<math.h>

void MattW_f(double *theta_p, double *theta_n, double g, double v, double x, double y) {
  double v2 = v*v;
  double gx = g*x;
  // No check against sqrt(negative number)
  double discriminant = sqrt(v2*v2 - g*(gx*x + 2*y*v2));
  if (theta_p) {
    // atan2() returns -pi to +pi, it is a 4 quadrant arctan.
    *theta_p = atan2(v2 + discriminant, gx);  
    }
  if (theta_n) {
    *theta_n = atan2(v2 - discriminant, gx);
    }
  }
于 2013-07-17T00:02:49.317 回答
0

如果您无法使用 arctan 方法,则可以使用准牛顿算法。

于 2013-07-16T15:17:58.257 回答
0

在你的最后一行,

theta = atan( equation / gx )

equation未设置。您可能想要替换topequation.

它还可以帮助您输出每个中间结果(gx、括号、sqrroot 和顶部)。看看是否有任何意想不到的中间结果。

于 2013-07-16T15:20:51.213 回答