我的方法返回0.0,但小的迭代逐步调试所有但不可能

时间:2016-05-11 04:20:50

标签: java game-physics

我对Java很陌生,我正在构建一个物理程序,它提供了通过墙壁击中目标所需的精确角度。将建造多种不同口径,枪管长度和充电强度的大炮。

我的第一个目标是通过墙壁并提供通过墙壁的角度范围。存在最大角度,其中炮弹击中远侧壁的顶部。有一个最小角度,可以受到球击中前侧或后侧的点的限制(取决于y轴速度是正面还是负面时通过背面)。

我不太熟悉语法等,我想知道我的minAngle()方法返回0.0是否有明显的原因,当这根本不可能时(在物理方面,除非墙的高度)小于初始高度)。提前抱歉我的方法效率低下:

public double minAngle(double MAX_INCLINE, double vInitial, double xWall1,double xWall2, double wallHeight, double yInitial, double barrelLength)
{
    double MIN_END=0;
    for(double currentTheta=0;currentTheta<MAX_INCLINE;currentTheta+=.001)
    {
        double t2 = (xWall2 - (barreLength*Math.acos(currentTheta))) / (vInitial*Math.acos(currentTheta));
        double WALL_END_HEIGHT = (0.5*g*Math.pow(t2, 2)) + (vInitial*Math.asin(currentTheta)*t2) + (barreLength * Math.asin(currentTheta) + yInitial);
        WALL_END_HEIGHT -= calibre/2;
        WALL_END_HEIGHT = Math.nextDown(WALL_END_HEIGHT * 1000)/1000;
        if (WALL_END_HEIGHT == wallHeight)
        {
            currentTheta = MIN_END;
            MIN_END = MIN_WALL;
        }
    }
    double t1 = (xWall1 - (barreLength*Math.acos(MIN_END))) / (vInitial*Math.acos(MIN_END));
    double WALL_START_HEIGHT = (0.5*g*Math.pow(t1, 2)) + (vInitial*Math.asin(MIN_END)*t1) + (barreLength * Math.asin(MIN_END) + yInitial);
    WALL_START_HEIGHT -= calibre/2;
    WALL_START_HEIGHT = Math.nextDown(WALL_START_HEIGHT * 1000)/1000;
    if(WALL_START_HEIGHT < wallHeight)
    {
        for(double currentTheta=MIN_END;currentTheta<MAX_INCLINE;currentTheta+=.001)
        {
            WALL_START_HEIGHT = (0.5*g*Math.pow(t1, 2)) + (vInitial*Math.asin(currentTheta)*t1) + (barreLength * Math.asin(currentTheta) + yInitial);
            WALL_START_HEIGHT -= calibre/2;
            WALL_START_HEIGHT = Math.nextDown(WALL_START_HEIGHT * 1000)/1000;
            if(WALL_START_HEIGHT == wallHeight)
            {
                currentTheta = MIN_WALL;
            }
        }
    }
    return MIN_WALL;
}

输入:minAngle(Math.PI / 2,590.9580509515898,20,21,10,0,5);

输出:0.0

0 个答案:

没有答案