Math 弧度atan2显示的是相反的值,然后才是它们需要的值

Math 弧度atan2显示的是相反的值,然后才是它们需要的值,math,geometry,trigonometry,radians,atan2,Math,Geometry,Trigonometry,Radians,Atan2,如何使各方面的值正确显示。 此时,如果我绕着点旋转,它将显示一个向外的运动,就像在实际点后面,当它应该让点始终指向点时。 而且它从179到-179,从未达到180 完整代码如下所示 radians 3.14 = 180 should be 0 radians 0 = 0 should be 180 radians -1.584827 = -90 should be 90 radians -1579912 = 90 should be -90 修正了它,只需翻转MyShip

如何使各方面的值正确显示。 此时,如果我绕着点旋转,它将显示一个向外的运动,就像在实际点后面,当它应该让点始终指向点时。 而且它从179到-179,从未达到180

完整代码如下所示

radians 3.14 = 180 should be 0
radians 0    =   0 should be 180 

radians -1.584827 =  -90 should be 90
radians -1579912  =   90 should be -90

修正了它,只需翻转MyShip的敌人值即可

而不是我的身份-敌人
你做敌我游戏的原因是你的画布坐标原点在左上角;将其更改为左下角,您的三角将更加标准。
radians 3.14 = 180 should be 0
radians 0    =   0 should be 180 

radians -1.584827 =  -90 should be 90
radians -1579912  =   90 should be -90
        /* Relative player position */
        float const dx = (MyShip.XCoordinate + 18) - (Enemy.XCoordinate + 18);
        float const dy = (MyShip.YCoordinate + 18) - (Enemy.YCoordinate + 18);
        /* Relative player velocity */
        float const vx = MyShip.XSpeed - Enemy.XSpeed;
        float const vy = MyShip.YSpeed - Enemy.YSpeed;

        float const a = vx * vx + vy * vy - bulletSpeed * bulletSpeed;
        float const b = 2.f * (vx * dx + vy * dy);
        float const c = dx * dx + dy * dy;
        float const discriminant = b * b - 4.f * a * c;

        int deg_to_aim = 0;

        if (discriminant >= 0) {
            float t0 = (float)(-b + sqrt(discriminant)) / (2 * a);
            float t1 = (float)(-b - sqrt(discriminant)) / (2 * a);

            if (t0 < 0.f || (t1 < t0 && t1 >= 0.f))
                t0 = t1;
            if (t0 >= 0.f)
            {
                // Aim at
                double shootx = vx + dx / t0;
                double shooty = vy + dy / t0;
                double radians = atan2((double)-shooty, shootx);
                deg_to_aim = (int)((radians * 360) / (2 * 3.141592653589793238462));
                myprintf("(A) radians = %f deg to aim = %d\n", radians, deg_to_aim);
            }
        }
        else {
            myprintf("Error found!!!!!!! no solution\n");
        }