限制纬度和经度值的模数 [英] Modulus to limit latitude and longitude values
问题描述
我有代表纬度和经度的双打.
我可以使用以下功能轻松地将经度限制为(-180.0,180.0] .
I have doubles that represent latitudes and longitudes.
I can easily limit longitudes to (-180.0, 180.0] with the following function.
double limitLon(double lon)
{
return fmod(lon - 180.0, 360.0) + 180.0;
}
之所以有用,是因为一端是排他的,而另一端是排他的.fmod包含0,但不包含-360.0.
This works because one end is exclusive and the other is inclusive. fmod includes 0 but not -360.0.
有人能想到一种优雅的纬度方法吗?
所需的时间间隔是 [-90.0,90.0] .封闭形式的解决方案是最好的,即没有循环.我认为fmod()可能不是入门者,因为现在两端都是包容性的.
Can anyone think of an elegant method for latitude?
The required interval is [-90.0, 90.0]. A closed form solution would be best, i.e. no loop. I think fmod() is probably a non-starter because both ends are inclusive now.
编辑:正如所指出的,无论如何,人们都无法达到91度纬度.从技术上讲91应该映射到89.0.哦,男孩,这改变了一切.
As was pointed out, one can't go to 91 degrees latitude anyway. Technically 91 should map to 89.0. Oh boy, that changes things.
推荐答案
如何使用 sin
和逆函数?
asin(sin((lat/180.0)*3.14159265)) * (180.0/3.14159265);
这篇关于限制纬度和经度值的模数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!