弧度 atan2 显示的值与它们需要的值相反

radian atan2 is showing opposite values then what they need to be

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);

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

如何使所有方面的值正确显示。 目前,如果我围绕该点旋转,它会显示出向外的运动,就像在实际点后面一样,而它应该始终指向该点。 它也从 179-179 从未达到 180.

完整代码如下所示

        /* 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");
        }

修复了它只是翻转 MyShip Enemy 值。

而不是MyShip - Enemy
你做 Enemy - MyShip