Geographical position and calculation using latitude/longitude. Most of this comes from http://www.movable-type.co.uk/scripts/latlong.html
GeoPosition.h@1:b4feb3f54fa3, 2011-09-27 (annotated)
- Committer:
- shimniok
- Date:
- Tue Sep 27 04:00:39 2011 +0000
- Revision:
- 1:b4feb3f54fa3
- Parent:
- 0:8b049ccf57cb
Added duplicate include protection, change macro PI to _PI to avoid conflict
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shimniok | 1:b4feb3f54fa3 | 1 | #ifndef __GEOPOSITION_H |
shimniok | 1:b4feb3f54fa3 | 2 | #define __GEOPOSITION_H |
shimniok | 1:b4feb3f54fa3 | 3 | |
shimniok | 1:b4feb3f54fa3 | 4 | #ifndef _PI |
shimniok | 1:b4feb3f54fa3 | 5 | #define _PI 3.141592653 |
shimniok | 0:8b049ccf57cb | 6 | #endif |
shimniok | 0:8b049ccf57cb | 7 | |
shimniok | 1:b4feb3f54fa3 | 8 | #define degrees(x) ((x)*180/_PI) |
shimniok | 1:b4feb3f54fa3 | 9 | #define radians(x) ((x)*_PI/180) |
shimniok | 0:8b049ccf57cb | 10 | |
shimniok | 0:8b049ccf57cb | 11 | /** Geographical position and calculation. Most of this comes from http://www.movable-type.co.uk/scripts/latlong.html |
shimniok | 0:8b049ccf57cb | 12 | * |
shimniok | 0:8b049ccf57cb | 13 | */ |
shimniok | 0:8b049ccf57cb | 14 | class GeoPosition { |
shimniok | 0:8b049ccf57cb | 15 | public: |
shimniok | 0:8b049ccf57cb | 16 | |
shimniok | 0:8b049ccf57cb | 17 | /** Create a new emtpy position object |
shimniok | 0:8b049ccf57cb | 18 | * |
shimniok | 0:8b049ccf57cb | 19 | */ |
shimniok | 0:8b049ccf57cb | 20 | GeoPosition(); |
shimniok | 0:8b049ccf57cb | 21 | |
shimniok | 0:8b049ccf57cb | 22 | /** Create a new position with the specified latitude and longitude. See set() |
shimniok | 0:8b049ccf57cb | 23 | * |
shimniok | 0:8b049ccf57cb | 24 | * @param latitude is the latitude to set |
shimniok | 0:8b049ccf57cb | 25 | * @param longitude is the longitude to set |
shimniok | 0:8b049ccf57cb | 26 | */ |
shimniok | 0:8b049ccf57cb | 27 | GeoPosition(double latitude, double longitude); |
shimniok | 0:8b049ccf57cb | 28 | |
shimniok | 0:8b049ccf57cb | 29 | /** Get the position's latitude |
shimniok | 0:8b049ccf57cb | 30 | * |
shimniok | 0:8b049ccf57cb | 31 | * @returns the position's latitude |
shimniok | 0:8b049ccf57cb | 32 | */ |
shimniok | 0:8b049ccf57cb | 33 | double latitude(); |
shimniok | 0:8b049ccf57cb | 34 | |
shimniok | 0:8b049ccf57cb | 35 | /** Get the position's longitude |
shimniok | 0:8b049ccf57cb | 36 | * |
shimniok | 0:8b049ccf57cb | 37 | * @returns the position's longitude |
shimniok | 0:8b049ccf57cb | 38 | */ |
shimniok | 0:8b049ccf57cb | 39 | double longitude(); |
shimniok | 0:8b049ccf57cb | 40 | |
shimniok | 0:8b049ccf57cb | 41 | /** Set the position's location to another position's coordinates |
shimniok | 0:8b049ccf57cb | 42 | * |
shimniok | 0:8b049ccf57cb | 43 | * @param pos is another position from which coordinates will be copied |
shimniok | 0:8b049ccf57cb | 44 | */ |
shimniok | 0:8b049ccf57cb | 45 | void set(GeoPosition pos); |
shimniok | 0:8b049ccf57cb | 46 | |
shimniok | 0:8b049ccf57cb | 47 | /** Set the position's location to the specified coordinates |
shimniok | 0:8b049ccf57cb | 48 | * |
shimniok | 0:8b049ccf57cb | 49 | * @param latitude is the new latitude to set |
shimniok | 0:8b049ccf57cb | 50 | * @param longitude is the new longitude to set |
shimniok | 0:8b049ccf57cb | 51 | */ |
shimniok | 0:8b049ccf57cb | 52 | void set(double latitude, double longitude); |
shimniok | 0:8b049ccf57cb | 53 | |
shimniok | 0:8b049ccf57cb | 54 | /** Move the location of the position by the specified distance and in |
shimniok | 0:8b049ccf57cb | 55 | * the specified direction |
shimniok | 0:8b049ccf57cb | 56 | * |
shimniok | 0:8b049ccf57cb | 57 | * @param course is the direction of movement in degrees, absolute not relative |
shimniok | 0:8b049ccf57cb | 58 | * @param distance is the distance of movement along the specified course in meters |
shimniok | 0:8b049ccf57cb | 59 | */ |
shimniok | 0:8b049ccf57cb | 60 | void move(float course, float distance); |
shimniok | 0:8b049ccf57cb | 61 | |
shimniok | 0:8b049ccf57cb | 62 | /** Get the bearing from the specified origin position to this position. To get |
shimniok | 0:8b049ccf57cb | 63 | * relative bearing, subtract the result from your heading. |
shimniok | 0:8b049ccf57cb | 64 | * |
shimniok | 0:8b049ccf57cb | 65 | * @param from is the position from which to calculate bearing |
shimniok | 0:8b049ccf57cb | 66 | * @returns the bearing in degrees |
shimniok | 0:8b049ccf57cb | 67 | */ |
shimniok | 0:8b049ccf57cb | 68 | float bearing(GeoPosition from); |
shimniok | 0:8b049ccf57cb | 69 | |
shimniok | 0:8b049ccf57cb | 70 | /** Get the distance from the specified origin position to this position |
shimniok | 0:8b049ccf57cb | 71 | * |
shimniok | 0:8b049ccf57cb | 72 | * @param from is the position from which to calculate distance |
shimniok | 0:8b049ccf57cb | 73 | * @returns the distance in meters |
shimniok | 0:8b049ccf57cb | 74 | */ |
shimniok | 0:8b049ccf57cb | 75 | float distance(GeoPosition from); |
shimniok | 0:8b049ccf57cb | 76 | |
shimniok | 0:8b049ccf57cb | 77 | /** Set an arbitrary timestamp on the position |
shimniok | 0:8b049ccf57cb | 78 | * |
shimniok | 0:8b049ccf57cb | 79 | * @param timestamp is an integer timestamp, eg., seconds, milliseconds, or whatever |
shimniok | 0:8b049ccf57cb | 80 | */ |
shimniok | 0:8b049ccf57cb | 81 | void setTimestamp(int time); |
shimniok | 0:8b049ccf57cb | 82 | |
shimniok | 0:8b049ccf57cb | 83 | /** Return a previously set timestamp on the position |
shimniok | 0:8b049ccf57cb | 84 | * |
shimniok | 0:8b049ccf57cb | 85 | * @returns the timestamp (e.g., seconds, milliseconds, etc.) |
shimniok | 0:8b049ccf57cb | 86 | */ |
shimniok | 0:8b049ccf57cb | 87 | int getTimestamp(void); |
shimniok | 0:8b049ccf57cb | 88 | |
shimniok | 0:8b049ccf57cb | 89 | private: |
shimniok | 0:8b049ccf57cb | 90 | double _R; /** Earth's mean radius */ |
shimniok | 0:8b049ccf57cb | 91 | double _latitude; /** The position's latitude */ |
shimniok | 0:8b049ccf57cb | 92 | double _longitude; /** The position's longitude */ |
shimniok | 0:8b049ccf57cb | 93 | double _northing; /** The position's UTM northing coordinate */ |
shimniok | 0:8b049ccf57cb | 94 | double _easting; /** The position's UTM easting coordinate */ |
shimniok | 0:8b049ccf57cb | 95 | int _time; /** Timestamp */ |
shimniok | 1:b4feb3f54fa3 | 96 | }; |
shimniok | 1:b4feb3f54fa3 | 97 | |
shimniok | 1:b4feb3f54fa3 | 98 | #endif |