Keith G
/
compass_test
Initial import
Diff: gps_utils.h
- Revision:
- 2:3a288d8c816b
diff -r 3812d4579de0 -r 3a288d8c816b gps_utils.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gps_utils.h Wed Mar 23 19:22:07 2016 +0000 @@ -0,0 +1,56 @@ +#ifndef __gps_utils_h__ +#define __gps_utils_h__ + +#include <math.h> + +#ifndef M_PI + #define M_PI 3.14159265358979323846 +#endif + +#define TWO_PI (M_PI+M_PI) + +#define EARTH_RADIUS_METERS 6371000 + +//Functions extracted from http://movable-type.co.uk/scripts/latlong.html + +// +// Calculate the distance between two points on earth using the haversine function. +// Most accurate and expensive distance calculating function in this library. +// lat and lon values expected in radians. +// Returns distance in meters +// +double haversine(double lat1, double lon1, double lat2, double lon2); + +// +// Calculate the distance between two points on earth using the spherical law of cosines. +// Less expencive than haversine, but not good at small distances. +// lat and lon values expected in radians. +// Returns distance in meters +// +double cosines(double lat1, double lon1, double lat2, double lon2); + +// +// Calculate the distance between two points on earth using equirectangular approximation. +// Least accurate and expensive distance calculating function, suitable only for small distances. +// lat and lon values expected in radians. +// Returns distance in meters +// +double equirectangular(double lat1, double lon1, double lat2, double lon2); + +// +// Calculates the inital bearing a journey requires if traveling from lat1,lon1 to lat2,lon2. +// (Bearing can naturally change as one travels along the sphere) +// lat and lon values expected in radians. +// Returns bearing in the range 0-2*PI +// +double startBearing(double lat1, double lon1, double lat2, double lon2); + +// +// Calculates the bearing a journey will end on if traveling from lat1,lon1 to lat2,lon2. +// (Bearing can naturally change as one travels along the sphere) +// lat and lon values expected in radians. +// Returns bearing in the range 0-2*PI +// +double endBearing(double lat1, double lon1, double lat2, double lon2); + +#endif //__gps_utils_h__ \ No newline at end of file