gpt4 book ai didi

c# - 半正弦公式Unity

转载 作者:太空狗 更新时间:2023-10-29 23:13:03 24 4
gpt4 key购买 nike

所以我试图在 Unity 中使用 haversine 公式来获得两个不同点之间的距离(给定的纬度和经度)。该代码正在运行(没有错误),但我一直得到错误的结果。我遵循了整个公式,所以我真的不知道数学/代码问题在哪里。有什么想法吗?

代码如下:

 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# - 半正弦公式Unity,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39111063/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com