c# – Haversine公式Unity
作者:互联网
所以我试图在Unity中使用hasrsine公式来获得两个不同点(纬度和纵向)之间的距离.代码正在运行(没有错误),但我一直在得到错误的结果.我遵循了整个公式,所以我真的不知道数学/代码问题在哪里.任何的想法?
这是代码:
public float lat1 = 42.239616f;
public float lat2 = -8.72304f;
public float lon1 = 42.239659f;
public float lon2 = -8.722305f;
void operacion(){
float R = 6371000; // metres
float omega1 = ((lat1/180)*Mathf.PI);
float omega2 = ((lat2/180)*Mathf.PI);
float variacionomega1 = (((lat2 - lat1)/180)*Mathf.PI);
float variacionomega2 = (((lon2 - lon1) / 180) * Mathf.PI);
float a = Mathf.Sin(variacionomega1/2) * Mathf.Sin(variacionomega1/2) +
Mathf.Cos(omega1) * Mathf.Cos(omega2) *
Mathf.Sin(variacionomega2/2) * Mathf.Sin(variacionomega2/2);
float c = 2 * Mathf.Atan2(Mathf.Sqrt(a), Mathf.Sqrt(1-a));
float d = R * c;
}
解决方法:
我认为这一行不正确:
float c = 2 * Mathf.Atan2(Mathf.Sqrt(a), Mathf.Sqrt(1-a));
更新:
正确的方法是:
float c = 2 * Mathf.Asin(Mathf.Sqrt(a));
标签:c,unity3d,haversine 来源: https://codeday.me/bug/20190623/1267852.html