我正在尝试将纬度和经度转换为 Vector3 格式。对于给定的纬度和经度,我想将其转换为 Vector3,其中标记对象将位于此 Vector3 位置。
这是我的代码:
void createLand()
{
double latitude_rad = (latitude) * Math.PI / 180;
double longitude_rad = (longitude) * Math.PI / 180;
double xPos = (radiusEarth * Math.Cos((latitude_rad)) * Math.Cos((longitude_rad)));
double yPos = (radiusEarth * Math.Cos((latitude_rad)) * Math.Sin((longitude_rad)));
double zPos = (radiusEarth * Math.Sin((latitude_rad)));
markerPos.x = (float)xPos;
markerPos.y = (float)yPos;
markerPos.z = (float)zPos;
ObjectMarker.position = markerPos;
}
我使用 6371 作为 radiusEarth,这是伦敦 lat:51.509865、lon:-0.118092 的输出:
这是北极的输出,纬度:90,经度:135:
标记(即闪亮的小球体)位置错误。
我的转换有什么问题吗?或者有其他方法可以解决这个问题吗?
EDIT...
我用过的地球纹理可以找到here http://planetpixelemporium.com/earth8081.html,这是10K图像。我构建了球体并使用 Blender 应用了纹理 - 我对球体应用了旋转,以便前视图将反映 lat,long: 0,0 的位置。
创建地球对象的代码:
void createEarth()
{
ObjectEarth.gameObject.transform.localScale = 1f * radiusEarth * Vector3.one;
}
编辑2...
这是使用 Unity 的预定义矢量时放置标记的位置:
void createLand()
{
ObjectMarker.position = radiusEarth * Vector3.forward;
}
void createLand()
{
ObjectMarker.position = radiusEarth * Vector3.right;
}
void createLand()
{
ObjectMarker.position = radiusEarth * Vector3.up;
}