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/environ_object.cpp

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 
00036 #include "environ_object.h"
00037 
00038 
00039 void Environ_object::__decimal2coord(Coordinates coord)
00040 {
00041         double c = coord.lat;
00042         coord.latitude.degrees = (int) floor(c);
00043         c -= coord.latitude.degrees;
00044         c *= 60;
00045         coord.latitude.minutes = abs((int) floor(c));
00046         c -= coord.latitude.minutes;
00047         c *= 60;
00048         coord.latitude.seconds = c;
00049 
00050         c = coord.lon;
00051         coord.longitude.degrees = (int) floor(c);
00052         c -= coord.longitude.degrees;
00053         c *= 60;
00054         coord.longitude.minutes = abs((int) floor(c));
00055         c -= coord.longitude.minutes;
00056         c *= 60;
00057         coord.longitude.seconds = c;
00058 }
00059 
00060 
00061 void Environ_object::__coord2decimal(Coordinates coord)
00062 {
00063         coord.lat = coord.latitude.seconds;
00064         coord.lat /= 60;
00065         coord.lat += coord.latitude.minutes;
00066         coord.lat /= 60;
00067         coord.lat += coord.latitude.degrees;
00068 
00069         coord.lon = coord.longitude.seconds;
00070         coord.lon /= 60;
00071         coord.lon += coord.longitude.minutes;
00072         coord.lon /= 60;
00073         coord.lon += coord.longitude.degrees;
00074 }
00075 
00076 
00077 void Environ_object::set_coordinates(Coordinates origin, double lat, 
00078                                      double lon, double alt)
00079 {
00080         double x, y;
00081         origin.coords2meters(lat, lon, &x, &y);
00082         dGeomSetPosition(shape, x, y, alt);
00083 
00084         coords.lat = lat;
00085         coords.lon = lon;
00086         coords.altitude = alt;
00087         __decimal2coord(coords);
00088 }
00089 
00090 
00091 void Environ_object::get_coordinates(double *lt, double *ln, double *alt)
00092 {
00093         *lt = coords.lat;
00094         *ln = coords.lon;
00095         *alt = coords.altitude;
00096 }
00097 
00098 
00099 void Environ_object::set_location(Coordinates origin, double x, 
00100                                   double y, double z)
00101 {
00102         dGeomSetPosition(shape, x, y, z);
00103         coords.altitude = z;
00104         origin.meters2coords(x, y, &coords.lat, &coords.lon);
00105 }
00106 
00107 
00108 void Environ_object::get_location(double *lt, double *ln, double *alt)
00109 {
00110         double *loc = (double*)dGeomGetPosition(shape);
00111 
00112         *lt = loc[0];
00113         *ln = loc[1];
00114         *alt = loc[2];
00115 }
00116 
00117 
00118 double Environ_object::distance(Environ_object *other)
00119 {
00120         double a_lat, a_lon, a_alt, b_lat, b_lon, b_alt;
00121         get_location(&a_lat, &a_lon, &a_alt);
00122         other->get_location(&b_lat, &b_lon, &b_alt);
00123 
00124         return sqrt(pow((a_lat - b_lat), 2) + 
00125                     pow((a_lon - b_lon), 2) + 
00126                     pow((a_alt - b_alt), 2));
00127 }


© 2007, Los Alamos National Security, LLC.