#sphere #geometry #navigation

no-std unit-sphere

A library for performing geometric calculations on the surface of a sphere

3 releases

new 0.1.2 Apr 26, 2024
0.1.1 Mar 10, 2024
0.1.0 Feb 25, 2024

#480 in Math

Download history 103/week @ 2024-02-23 23/week @ 2024-03-01 141/week @ 2024-03-08 21/week @ 2024-03-15 4/week @ 2024-03-22 42/week @ 2024-03-29 3/week @ 2024-04-05 152/week @ 2024-04-12

201 downloads per month
Used in icao-wgs84

MIT license

87KB
1.5K SLoC

unit-sphere

crates.io docs.io License Rust codecov

A library for performing geometric calculations on the surface of a sphere.

The library uses a combination of spherical trigonometry and vector geometry to perform great-circle navigation on the surface of a unit sphere, see Figure 1.

great circle path
Figure 1 A Great Circle Path

A great circle is the shortest path between positions on the surface of a sphere.
It is the spherical equivalent of a straight line in planar geometry.

Spherical trigonometry

A great circle path between positions may be calculated using spherical trigonometry.

The course (initial azimuth) of a great circle can be calculated from the latitudes and longitudes of the start and end points.
While great circle distance can also be calculated from the latitudes and longitudes of the start and end points using the haversine formula.
The resulting distance in Radians can be converted to the required units by multiplying the distance by the Earth radius measured in the required units.

Vector geometry

Points on the surface of a sphere and great circle poles may be represented by 3D vectors.
Many calculations are simpler using vectors than spherical trigonometry.

Spherical Vector Coordinates
Figure 2 Spherical Vector Coordinates

For example, the across track distance of a point from a great circle can be calculated from the dot product of the point and the great circle pole vectors. While the intersection points of great circles can simply be calculated from the cross product of their pole vectors.

Design

The great_circle module performs spherical trigonometric calculations and the vector module performs vector geometry calculations.

Sphere Class Diagram
Figure 3 Class Diagram

The library is declared no_std so it can be used in embedded applications.

Contribution

If you want to contribute through code or documentation, the Contributing guide is the best place to start. If you have any questions, please feel free to ask. Just please abide by our Code of Conduct.

License

unit-sphere is provided under a MIT license, see LICENSE.

Dependencies

~4.5MB
~91K SLoC