简体   繁体   中英

How to convert Latitude and Longitude to Orientation (Yaw, Pitch, Roll)

I have a 3D aircraft model in WorldWind a 3D earth model which runs on OpenGL Java. I update the position of this model with data from an database that includes lat, lon, and alt. What is the method to get the heading information (Yaw, pitch, roll) from current position and update position?

I figured it out, with latitude longitude and altitude I converted them into ECEF coords. Then found the direction from

        d(x,y,z) = (Destination(x,y,z) - Origin(x,y,z))

        double yaw   = -Math.atan2(dx,-dz);
        double pitch = Math.atan2(dy, Math.sqrt((dx * dx) + (dz * dz)));

This is user758114 for the advice and incredible solution. This is just the same script but in #C. This works with a GeoLocation API, so this is tested.

class ECEF
{
    public static (double, double) GetOrientation(SomeGeoLocation item1, SomeGeoLocation item2)
    {
        return OrientationDifference((item1.Latitude - item2.Latitude, 
            item1.Altitude- item2.Altitude, 
            item1.Longitude - item2.Longitude));
    }

    private static (double, double) OrientationDifference((double, double, double) orientDIff)
    {
        return (yaw(orientDIff.Item2, orientDIff.Item3), pitch(orientDIff.Item1, orientDIff.Item2, orientDIff.Item3));
    }

    private static double yaw(double dx, double dz) => -Math.Atan2(dx, -dz);

    private static double pitch(double dx, double dy, double dz) => Math.Atan2(dy, Math.Sqrt((dx * dx) + dz * dz));
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM