大地坐标系(WGS84)转空间直角坐标系(笛卡尔坐标系XYZ)

大地坐标系(WGS84)转空间直角坐标系(笛卡尔坐标系XYZ)

以Unity为例
大地坐标系(WGS84)转空间直角坐标系(笛卡尔坐标系XYZ)
float[] get_coordinate( float lat, float lon,float H1)
{
//H指的就是距离海平面的大地高,N+H也就是当前测点与地心的矢径
float f = 1f / 298.257223563f;
float b = 6378245f * (1 - f);
float e = Mathf.Sqrt(6378245f * 6378245f - b * b) / 6378245f;
float N = 6378245f / Mathf.Sqrt(1 - e * e * Mathf.Sin(lat * Mathf.PI / 180) * Mathf.Sin(lat * Mathf.PI / 180));
float WGS84_X = (N + H1) * Mathf.Cos(lat * Mathf.PI / 180) * Mathf.Cos(lon * Mathf.PI / 180);
float WGS84_Y = (N + H1) * Mathf.Cos(lat * Mathf.PI / 180) * Mathf.Sin(lon * Mathf.PI / 180);
float WGS84_Z = (N * (1 - (e * e)) + H1) * Mathf.Sin(lat * Mathf.PI / 180);
float[] res = { WGS84_X, WGS84_Y, WGS84_Z };
return res;
}

for (int i = -90; i <= 90; i+=2)
{
for (int j = -180; j <= 180; j+=5)
{
float[] res = get_coordinate(i, j, 6378245f);
res[0] /= 100000f; res[1] /= 100000f; res[2] /= 100000f;
GameObject gb = GameObject.CreatePrimitive(PrimitiveType.Cube);
gb.transform.position = new Vector3(res[0], res[2], res[1]);
}
}