在ue中,做了个地球仪。发现经纬度转地心坐标系老是出问题。后来发现,是转ue时,x,y坐标要互换。
也对,因为在cesium for unreal中还有一系列ecef转ue的相关函数。
即下面的代码中,xy需要互换,在ue中才能正常使用。偏心率为0时椭球体退化为球体。
FVectorGetXYZFromLonlatHeight(double radius ,double lon, double lat, double height)
{
#if 0
double e2 = 0.00669438002290;
#endif
#if 1
double e2 = 0;
#endif
#if 1
//转换为弧度
double L = lon * PI / 180.0;//经度
double B = lat * PI / 180.0;//纬度
double h = height;
double fac1 = 1 - e2 * FGenericPlatformMath::Sin(B) * FGenericPlatformMath::Sin(B);
double N = radius / FGenericPlatformMath::Sqrt(fac1);
double X = (N + h) * FGenericPlatformMath::Cos(B) * FGenericPlatformMath::Cos(L);
double Y = (N + h) * FGenericPlatformMath::Cos(B) * FGenericPlatformMath::Sin(L);
double Z = (N * (1 - e2) + h) * FGenericPlatformMath::Sin(B);
FVector xyz = FVector(X, Y, Z);
return xyz;
#endif
}