Keith G
/
compass_test
Initial import
gps_utils.h@3:af291e8853b1, 2016-03-24 (annotated)
- Committer:
- Condo2k4
- Date:
- Thu Mar 24 16:40:18 2016 +0000
- Revision:
- 3:af291e8853b1
- Parent:
- 2:3a288d8c816b
Compass Calibration
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Condo2k4 | 2:3a288d8c816b | 1 | #ifndef __gps_utils_h__ |
Condo2k4 | 2:3a288d8c816b | 2 | #define __gps_utils_h__ |
Condo2k4 | 2:3a288d8c816b | 3 | |
Condo2k4 | 2:3a288d8c816b | 4 | #include <math.h> |
Condo2k4 | 2:3a288d8c816b | 5 | |
Condo2k4 | 2:3a288d8c816b | 6 | #ifndef M_PI |
Condo2k4 | 2:3a288d8c816b | 7 | #define M_PI 3.14159265358979323846 |
Condo2k4 | 2:3a288d8c816b | 8 | #endif |
Condo2k4 | 2:3a288d8c816b | 9 | |
Condo2k4 | 2:3a288d8c816b | 10 | #define TWO_PI (M_PI+M_PI) |
Condo2k4 | 2:3a288d8c816b | 11 | |
Condo2k4 | 2:3a288d8c816b | 12 | #define EARTH_RADIUS_METERS 6371000 |
Condo2k4 | 2:3a288d8c816b | 13 | |
Condo2k4 | 2:3a288d8c816b | 14 | //Functions extracted from http://movable-type.co.uk/scripts/latlong.html |
Condo2k4 | 2:3a288d8c816b | 15 | |
Condo2k4 | 2:3a288d8c816b | 16 | // |
Condo2k4 | 2:3a288d8c816b | 17 | // Calculate the distance between two points on earth using the haversine function. |
Condo2k4 | 2:3a288d8c816b | 18 | // Most accurate and expensive distance calculating function in this library. |
Condo2k4 | 2:3a288d8c816b | 19 | // lat and lon values expected in radians. |
Condo2k4 | 2:3a288d8c816b | 20 | // Returns distance in meters |
Condo2k4 | 2:3a288d8c816b | 21 | // |
Condo2k4 | 2:3a288d8c816b | 22 | double haversine(double lat1, double lon1, double lat2, double lon2); |
Condo2k4 | 2:3a288d8c816b | 23 | |
Condo2k4 | 2:3a288d8c816b | 24 | // |
Condo2k4 | 2:3a288d8c816b | 25 | // Calculate the distance between two points on earth using the spherical law of cosines. |
Condo2k4 | 2:3a288d8c816b | 26 | // Less expencive than haversine, but not good at small distances. |
Condo2k4 | 2:3a288d8c816b | 27 | // lat and lon values expected in radians. |
Condo2k4 | 2:3a288d8c816b | 28 | // Returns distance in meters |
Condo2k4 | 2:3a288d8c816b | 29 | // |
Condo2k4 | 2:3a288d8c816b | 30 | double cosines(double lat1, double lon1, double lat2, double lon2); |
Condo2k4 | 2:3a288d8c816b | 31 | |
Condo2k4 | 2:3a288d8c816b | 32 | // |
Condo2k4 | 2:3a288d8c816b | 33 | // Calculate the distance between two points on earth using equirectangular approximation. |
Condo2k4 | 2:3a288d8c816b | 34 | // Least accurate and expensive distance calculating function, suitable only for small distances. |
Condo2k4 | 2:3a288d8c816b | 35 | // lat and lon values expected in radians. |
Condo2k4 | 2:3a288d8c816b | 36 | // Returns distance in meters |
Condo2k4 | 2:3a288d8c816b | 37 | // |
Condo2k4 | 2:3a288d8c816b | 38 | double equirectangular(double lat1, double lon1, double lat2, double lon2); |
Condo2k4 | 2:3a288d8c816b | 39 | |
Condo2k4 | 2:3a288d8c816b | 40 | // |
Condo2k4 | 2:3a288d8c816b | 41 | // Calculates the inital bearing a journey requires if traveling from lat1,lon1 to lat2,lon2. |
Condo2k4 | 2:3a288d8c816b | 42 | // (Bearing can naturally change as one travels along the sphere) |
Condo2k4 | 2:3a288d8c816b | 43 | // lat and lon values expected in radians. |
Condo2k4 | 2:3a288d8c816b | 44 | // Returns bearing in the range 0-2*PI |
Condo2k4 | 2:3a288d8c816b | 45 | // |
Condo2k4 | 2:3a288d8c816b | 46 | double startBearing(double lat1, double lon1, double lat2, double lon2); |
Condo2k4 | 2:3a288d8c816b | 47 | |
Condo2k4 | 2:3a288d8c816b | 48 | // |
Condo2k4 | 2:3a288d8c816b | 49 | // Calculates the bearing a journey will end on if traveling from lat1,lon1 to lat2,lon2. |
Condo2k4 | 2:3a288d8c816b | 50 | // (Bearing can naturally change as one travels along the sphere) |
Condo2k4 | 2:3a288d8c816b | 51 | // lat and lon values expected in radians. |
Condo2k4 | 2:3a288d8c816b | 52 | // Returns bearing in the range 0-2*PI |
Condo2k4 | 2:3a288d8c816b | 53 | // |
Condo2k4 | 2:3a288d8c816b | 54 | double endBearing(double lat1, double lon1, double lat2, double lon2); |
Condo2k4 | 2:3a288d8c816b | 55 | |
Condo2k4 | 2:3a288d8c816b | 56 | #endif //__gps_utils_h__ |