N-sim
Emulation and simulation of
Wireless Sensor Networks



   Home


   Project Page


   Download


   CVS



   Installation


   Configuration


   Plug-ins




 Hosted by
SourceForge.net Logo

/home/brennan/n-sim/OrbisQuartus/shared/coordinates.h

Go to the documentation of this file.
00001 
00014 /*
00015  * Copyright 2007. Los Alamos National Security, LLC. This material
00016  * was produced under U.S. Government contract DE-AC52-06NA25396 for
00017  * Los Alamos National Laboratory (LANL), which is operated by Los
00018  * Alamos National Security, LLC, for the Department of Energy. The
00019  * U.S. Government has rights to use, reproduce, and distribute this
00020  * software. NEITHER THE GOVERNMENT NOR LOS ALAMOS NATIONAL SECURITY,
00021  * LLC, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR ASSUMES ANY LEGAL
00022  * LIABILITY FOR THE USE OF THIS SOFTWARE. If software is modified to
00023  * produce derivative works, such modified software should be clearly
00024  * marked, so as not to confuse it with the version available from LANL.
00025  *
00026  * Additionally, this program is free software; you can redistribute
00027  * it and/or modify it under the terms of the GNU General Public
00028  * License as published by the Free Software Foundation; version 2 of
00029  * the License. Accordingly, this program is distributed in the hope
00030  * it will be useful, but WITHOUT ANY WARRANTY; without even the
00031  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00032  * PURPOSE. See the GNU General Public License for more details.
00033  */
00034 
00035 #ifndef _COORDINATES_H_
00036 #define _COORDINATES_H_
00037 
00038 #include <string.h>
00039 #include "oq.h"
00040 
00041 
00042 class Coordinate {
00043  public:
00044         signed int degrees;
00045         unsigned int minutes;
00046         double seconds;
00047 
00048         Coordinate() { degrees = 0; minutes = 0; seconds = 0; };
00049 };
00050 
00051 
00052 class Coordinates {
00053         char _ellipsoid[MAX_NAME];
00054         double _geoid_diff;
00055                /* height (in m) of mean sea level above ellipsoid */
00056         static const double _K_ZERO = 0.9996;  /* scale along longitude */
00057 
00058         int _reference_ellipsoid_index(const char *name);
00059         double _rad_distance(double lat1, double lon1, 
00060                              double lat2, double lon2);
00061 
00062 public:
00063         static const unsigned int _GLOBAL_ELLIPSOIDS = 30;
00064 
00065         Coordinate latitude;
00066         Coordinate longitude;
00067 
00068         double lat;
00069         double lon;
00070         double altitude;  /* in meters */
00071 
00072         Coordinates() {
00073                 strcpy(_ellipsoid, "WGS 84");
00074                 _geoid_diff = 0.0;
00075                 lat = lon = altitude = 0;
00076         };
00077         Coordinates(double lt, double ln, double alt) {
00078                 strcpy(_ellipsoid, "WGS 84");
00079                 _geoid_diff = 0.0;
00080                 lat = lt; lon = ln; altitude = alt;
00081         };
00082         Coordinates(const Coordinates *c) { 
00083                 strcpy(_ellipsoid, "WGS 84");
00084                 _geoid_diff = 0.0;
00085                 latitude = c->latitude; 
00086                 longitude = c->longitude; 
00087                 altitude = c->altitude; 
00088         };
00089 
00090         char *get_ellipsoid() { return _ellipsoid; };
00091         double get_geoid_diff() { return _geoid_diff; };
00092         void set_ellipsoid(char *type);
00093         int list_reference_ellipsoids(char *names[], unsigned int *len);
00094 
00095         void coords2meters(double lat, double lon, double *x, double *y);
00096         void meters2coords(double x, double y, double *lat, double *lon);
00097         double coord_distance(double lat1, double lon1, 
00098                               double lat2, double lon2);
00099 };
00100 
00101 
00102 static const struct {
00103         char *name;
00104         double equatorial_radius; /* semi-major axis, 'a', in meters */
00105         double inverse_flattening;  /* 1/f */ 
00106 } reference_ellipsoids[Coordinates::_GLOBAL_ELLIPSOIDS] = 
00107 {
00108         {"Airy 1830", 6377563.396, 299.3249646},
00109         {"Australian National 1966", 6378160, 298.25},
00110         {"Bessel 1841", 6377397.155, 299.1528128},
00111         {"Bessel Namibia 1841", 6377483.865, 299.1528128},
00112         {"Clarke 1866", 6378206.4, 294.9786982},
00113         {"Clarke 1880", 6378249.145, 293.465},
00114         {"Everest 1830", 6377276.345, 300.801697979},
00115         {"Fischer 1960", 6378166.0, 298.3},
00116         {"Fischer 1968", 6378150.0, 298.3},
00117         {"GRS 67", 6378160.0, 298.247167427},
00118         {"GRS 80", 6378137.0, 298.257222101},
00119         {"Hayford 1910", 6378388.0, 297.0},
00120         {"Helmert 1906", 6378200.0, 298.3},
00121         {"Hough", 6378270.0, 297.0},
00122         {"IERS 1989", 6378136.0, 298.257},
00123         {"International 1924", 6378388.0, 297.0},
00124         {"Krassovsky 1940", 6378245.0, 298.3},
00125         {"Mercury 1960", 6378166.0, 298.3},
00126         {"Modified Airy", 6377340.189, 299.3249646},
00127         {"Modified Everest", 6377304.063, 300.801699969},
00128         {"Modified Fischer 1960", 6378155.0, 298.3},
00129         {"Modified Mercury 1968", 6378150.0, 298.3},
00130         {"NAD 27", 6378206.4, 294.978698208},
00131         {"NAD 83", 6378137.0, 298.257024899},
00132         {"New International 1967", 6378157.5, 298.24961539},
00133         {"South American 1969", 6378160.0, 298.25},
00134         {"WGS 60", 6378165.0, 298.3},
00135         {"WGS 66", 6378145.0, 298.25},
00136         {"WGS 72", 6378135.0, 298.26},
00137         {"WGS 84", 6378137, 298.257223563}
00138 };
00139 /* NB: 
00140  *    f = (a - b) / a   [i.e. semi-minor axis b = a - (a * f)]
00141  *    e^2 = f * (2 - f) = (a^2 - b^2) / a^2 
00142  *    e_prime^2 = (a^2 - b^2) / b^2 
00143  *
00144  * reference ellipsoids: 
00145  *    Wikipedia - http://en.wikipedia.org/wiki/Figure_of_the_Earth
00146  *    DB2 Spatial and Geodetic Extenders (IBM) - http://publib.boulder.ibm.com/infocenter/db2luw/v8/index.jsp?topic=/com.ibm.db2.udb.doc/opt/rsbp4119.htm
00147  */
00148 
00149 
00150 #endif  // _COORDINATES_H_


© 2007, Los Alamos National Security, LLC.