Skip to content
Advertisement

Looking for a way to reverse pan/tilt orientation back to x, y

I have something like follows: Input x, y and h to get pan and tilt orientation

        double dz = Math.sqrt( x*x + y*y );
        double rotPan = Math.toDegrees(Math.atan(x / y));
        double rotTilt = Math.toDegrees(Math.atan( h / dz ));

Is it possible to reverse the effect of Math only with h given to starting point and reach the initial x and y values?

Advertisement

Answer

double x = dz * Math.sin(Math.toRadians(rotPan)); 
double y = dz * Math.cos(Math.toRadians(rotPan));

Unfortunately, it is not possible to restore the initial values completely.

For example, x = 2 and y = 5 will give you exactly the same dz, rotPan (and rotTilt, which is not needed), as x = -2 and y = -5. So the best you can do is to restore (x, y) with a possible change of sign for both coordinates. Btw, you could avoid this problem, if you use atan2 function instead of atan:

double dz = Math.hypot(x, y);
double rotPan = Math.toDegrees(Math.atan2(x, y));
double rotTilt = Math.toDegrees(Math.atan2(h, dz));

If you use the above formulas to calculate rotPan and rotTilt, then the formulas at the top of my post will always give you the initial coordinates (with the limits of the numerical errors).

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement