1 个不稳定版本
0.1.0 | 2019年2月20日 |
---|
#4 in #doi
244 每月下载量
在 2 crates 中使用
145KB
3K SLoC
GeographicLib
Rust 对 GeographicLib 的接口
解决大圆问题的库
用法
将此内容添加到您的 Cargo.toml
[dependencies]
geographiclib = "0.1.0"
示例
use geographiclib::Geodesic;
let g = Geodesic::wgs84();
let (lat1, lon1) = (37.87622, -122.23558); // Berkeley, California
let (lat2, lon2) = (-9.4047, 147.1597); // Port Moresby, New Guinea
let (d_deg, d_m, az1, az2) = g.inverse(lat1, lon1, lat2, lon2);
assert_eq!(d_deg, 96.39996198449684); // Distance in degrees
assert_eq!(d_m, 10700471.955233702); // Distance in meters
assert_eq!(az1, -96.91639942294974); // Azimuth at (lat1, lon1)
assert_eq!(az2, -127.32548874543627); // Azimuth at (lat2, lon2)
许可证
此版本与 GeographicLib 使用相同的许可证;MIT/X11 许可证
lib.rs
:
GeographicLib 的 Rust 接口,用于大圆计算
注意:直接从 geodesic.h 复制。更多和更好的信息可以在那里找到。
这是在 C 中实现的大圆算法(带有 Rust 接口),这些算法在以下文献中描述:
示例
use geographiclib::Geodesic;
let g = Geodesic::wgs84();
let (lat1, lon1) = (37.87622, -122.23558); // Berkeley, California
let (lat2, lon2) = (-9.4047, 147.1597); // Port Moresby, New Guinea
let (d_deg, d_m, az1, az2) = g.inverse(lat1, lon1, lat2, lon2);
assert_eq!(d_deg, 96.39996198449684); // Distance in degrees
assert_eq!(d_m, 10700471.955233702); // Distance in meters
assert_eq!(az1, -96.91639942294974); // Azimuth at (lat1, lon1)
assert_eq!(az2, -127.32548874543627); // Azimuth at (lat2, lon2)
原理
与先前算法(例如,Vincenty,1975)相比,这些算法的主要优点是
- accurate to round off for |f| < 1/50;
- the solution of the inverse problem is always found;
- differential and integral properties of geodesics are computed.
在(lat1, lon1)和(lat2, lon2)两点之间的椭球面上的最短路径称为大圆。其长度为 s12,从点 1 到点 2 的大圆在两个端点具有前向方位角 azi1 和 azi2。
传统上考虑两种大圆问题
- [direct](struct.Geodesic.html#method.direct) – given lat1, lon1, s12, and azi1, determine lat2, lon2, and azi2.
- [inverse](struct.Geodesic.html#method.inverse) – given lat1, lon1, and lat2, lon2, determine s12, azi1, and azi2.
椭球体由其赤道半径 a(通常以米为单位)和偏心率 f 来指定。只要 |f| < 1/50,这些例程的精度就足以进行舍入,并使用双精度算术。对于 WGS84 椭球体,误差小于 15 纳米。(对于 |f| < 1/5,可以获得合理准确的结果。)对于长椭球体,指定 f < 0。
无运行时依赖项
~180KB