2013-07-16 111 views
0

这看起来像是一个难以置信的简单问题,但我发现的一切都太复杂了,以至于我无法理解。通过代码解决弹道方程

我有这个基本的弹道式:

ballistic trajectory

既然我知道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) 
+1

这不是一个二次方程.... – Dan455

+0

向下打破方程成小的离散步骤。为gx解决。解决gx平方。求解2yv平方。等等,直到你有theta。 –

+0

@ Dan455这是什么? –

回答

0

如果您没有访问反正切方法,可以使用拟牛顿算法。

+0

我不知道拟牛顿算法是什么。 –

0

在你的最后一行,

theta = atan(equation/gx) 

equation未设置。您可能想用top代替equation

它也可能有助于您输出每个中间结果(gx,括号,sqrroot和顶部)。看看是否有任何意外的中间结果。

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

+0

我只生成了+方程的代码。我已经使用上面的解决方案更新了我的帖子中的代码。 –

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。

0

A C溶液

#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); 
    } 
    } 
相关问题