计算两个纬度和经度坐标之间的距离和方位角。
我一直在尝试计算两个经纬度坐标之间的方位角,但有些难以理解这个概念。
我已经访问了http://www.movable-type.co.uk/scripts/latlong.html,并已经能够将距离代码更改为适用于lua,但是段落下的方位角代码使我有些困惑。
local y = Math.sin(dLon) * Math.cos(lat2)
local x = Math.cos(lat1)*Math.sin(lat2) - Math.sin(lat1)*Math.cos(lat2)*Math.cos(dLon)
local brng = Math.atan2(y, x).toDeg()
变量的命名(lat1、lat2、dLon)使我感到困惑。
如果我的初始经纬度是:
纬度= -33.8830555556 经度= 151.216666667
我的目标经纬度是:
纬度=22.25 经度=114.1667
哪些变量需要匹配到哪些经度和纬度?
dLon变量是否指两点经度之间的距离?
非常感谢!
尝试这个
local function geo_distance(lat1, lon1, lat2, lon2) if lat1 == nil or lon1 == nil or lat2 == nil or lon2 == nil then return nil end local dlat = math.rad(lat2-lat1) local dlon = math.rad(lon2-lon1) local sin_dlat = math.sin(dlat/2) local sin_dlon = math.sin(dlon/2) local a = sin_dlat * sin_dlat + math.cos(math.rad(lat1)) * math.cos(math.rad(lat2)) * sin_dlon * sin_dlon local c = 2 * math.atan2(math.sqrt(a), math.sqrt(1-a)) -- 6378 km is the earth's radius at the equator. -- 6357 km would be the radius at the poles (earth isn't a perfect circle). -- Thus, high latitude distances will be slightly overestimated -- To get miles, use 3963 as the constant (equator again) local d = 6378 * c return d end
```
输入的坐标是以度为单位的,所以
geo_distance(30.19, 71.51, 31.33, 74.21) = 约287公里
下面是一段我创建并运转完美的函数。在 X-Plane 飞行模拟器上进行了严格测试。在函数结尾,地球半径被除以 1852,以便函数返回海里数的距离。
function GC_distance_calc(lat1, lon1, lat2, lon2)
--该函数返回2个点之间的大圆距离。
--来源于:http://bluemm.blogspot.gr/2007/01/excel-formula-to-calculate-distance.html
--lat1, lon1 = 起始点的坐标(或飞机的)/ lat2, lon2是目标航点的坐标。
--6371km是地球的平均半径(米)。由于 X-Plane 使用的半径是 6378 公里,并没有太大区别,
--(在 6000 公里处约为5海里),因此我们将使用相同的值。
--其他我测试过的公式,当纬度处于不同的半球(东西)时,似乎会出现错误。
local distance = math.acos(math.cos(math.rad(90-lat1))*math.cos(math.rad(90-lat2))+
math.sin(math.rad(90-lat1))*math.sin(math.rad(90-lat2))*math.cos(math.rad(lon1-lon2))) * (6378000/1852)
return distance
end
- 如何将两个不同的lua文件合成一个 东西有点长 大佬请耐心看完 我是小白研究几天了都没搞定
- 如何在roblox studio中1:1导入真实世界的地形?
- 求解,lua_resume的第二次调用继续执行协程问题。
- 【上海普陀区】内向猫网络招募【Skynet游戏框架Lua后端程序员】
- SF爱好求教:如何用lua实现游戏内调用数据库函数实现账号密码注册?
- Lua实现网站后台开发
- LUA错误显式返回,社区常见的规约是怎么样的
- lua5.3下载库失败
- 请问如何实现文本框内容和某个网页搜索框内容连接,并把网页输出来的结果反馈到另外一个文本框上
- lua lanes多线程使用
- 一个kv数据库
- openresty 有没有比较轻量的 docker 镜像
- 想问一下,有大佬用过luacurl吗
- 在Lua执行过程中使用Load函数出现问题
- 为什么 neovim 里没有显示一些特殊字符?
- Lua比较两个表的值(不考虑键的顺序)
- 有个lua简单的项目,外包,有意者加微信 liuheng600456详谈,最好在成都
- 如何在 Visual Studio 2022 中运行 Lua 代码?
- addEventListener 返回 nil Lua
- Lua中获取用户配置主目录的跨平台方法
根据 JavaScript 代码,
lat1是初始点的纬度,lat2是目标点的纬度。注意所有纬度和经度都必须以弧度为单位;使用
math.rad()进行转换。此外,Lua 中的数学库称为
math,而不是Math。