00001 #ifndef GEOGRAPHIC_H
00002 #define GEOGRAPHIC_H
00003
00004 #include <math.h>
00005
00006 #define pi 3.14159265358979323846
00007
00008
00009
00010
00011 double deg2rad(double deg) {
00012 return (deg * pi / 180);
00013 }
00014
00015
00016
00017
00018 double rad2deg(double rad) {
00019 return (rad * 180 / pi);
00020 }
00021
00022 double haversineDistanceInMeters(double lat1, double lon1, double lat2, double lon2) {
00023 double theta, dist;
00024 theta = lon1 - lon2;
00025 dist = sin(deg2rad(lat1)) * sin(deg2rad(lat2)) + cos(deg2rad(lat1)) * cos(deg2rad(lat2)) * cos(deg2rad(theta));
00026 dist = acos(dist);
00027 dist = rad2deg(dist);
00028 dist = dist * 60 * 1.1515;
00029 dist = dist * 1609.344;
00030 return (dist);
00031 }
00032
00033 double euclideanDistance( double x1, double y1, double x2, double y2)
00034 {
00035 return ceil(sqrt(pow(abs( x1 - x2),2) + pow(abs( y1 - y2),2)));
00036 }
00037
00038 #endif //GEOGRAPHIC_H