我在 WorldWind 中有一个 3D 飞机模型,这是一个在 OpenGL Java 上运行的 3D 地球模型。我使用数据库中的数据(包括纬度、经度和替代度)更新此模型的位置。如何从当前位置获取航向信息(Yaw、Pitch、Roll)并更新位置?
我想通了,我将纬度、经度和海拔高度转换为 ECEF 坐标。然后找到了从
出发的方向 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)));
这是用户758114,寻求建议和令人难以置信的解决方案。这是相同的脚本,但使用的是 #C。这适用于 GeoLocation API,因此已经过测试。
class ECEF {
public static class OrientationResult {
public double yaw;
public double pitch;
public OrientationResult(double yaw, double pitch) {
this.yaw = yaw;
this.pitch = pitch;
}
}
public static OrientationResult getOrientation(double lat1, double alt1, double lon1, double lat2, double alt2, double lon2) {
double dx = lat1 - lat2;
double dy = alt1 - alt2;
double dz = lon1 - lon2;
return orientationDifference(dx, dy, dz);
}
private static OrientationResult orientationDifference(double dx, double dy, double dz) {
double yaw = -Math.atan2(dx, -dz);
double pitch = Math.atan2(dy, Math.sqrt((dx * dx) + dz * dz));
return new OrientationResult(yaw, pitch);
}
}