生成 gis经纬度转unity游戏世界坐标代码
时间: 2023-12-04 12:02:12 浏览: 280
以下是将GIS经纬度坐标系转换为Unity游戏世界坐标系的代码:
```csharp
using UnityEngine;
public static class GisToUnityConverter {
// 地球半径(米)
private const float EarthRadius = 6371000f;
// Unity坐标系中的1个单位表示的距离(米)
private const float UnityDistanceUnit = 1f;
// 经度1度所表示的弧度值
private const float RadianPerDegree = Mathf.PI / 180f;
// 将经纬度坐标转换为Unity游戏世界坐标
public static Vector3 ConvertToUnity(float longitude, float latitude) {
float x = EarthRadius * Mathf.Cos(latitude * RadianPerDegree) * Mathf.Cos(longitude * RadianPerDegree);
float z = EarthRadius * Mathf.Cos(latitude * RadianPerDegree) * Mathf.Sin(longitude * RadianPerDegree);
float y = 0f;
return new Vector3(x / UnityDistanceUnit, y / UnityDistanceUnit, z / UnityDistanceUnit);
}
}
```
使用方法:调用`ConvertToUnity`方法,传入经度和纬度,即可得到Unity游戏世界坐标。例如:
```csharp
float longitude = 116.4074f;
float latitude = 39.9042f;
Vector3 unityPos = GisToUnityConverter.ConvertToUnity(longitude, latitude);
```
阅读全文
相关推荐


















