root / ezdop / src / host / hunter / src / spherical.cc @ 676acd5c
History | View | Annotate | Download (2.1 kB)
| 1 | /*
|
|---|---|
| 2 | Copyright 2006 Johnathan Corgan. |
| 3 | |
| 4 | This program is free software; you can redistribute it and/or modify |
| 5 | it under the terms of the GNU General Public License version 2 |
| 6 | as published by the Free Software Foundation. |
| 7 | |
| 8 | This software is distributed in the hope that it will be useful, |
| 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | GNU General Public License for more details. |
| 12 | |
| 13 | You should have received a copy of the GNU General Public License |
| 14 | along with GNU Radio; see the file COPYING. If not, write to |
| 15 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 16 | Boston, MA 02111-1307, USA. |
| 17 | */ |
| 18 | |
| 19 | // Application level includes
|
| 20 | #include "spherical.h" |
| 21 | #include "util.h" |
| 22 | |
| 23 | Spherical::Spherical() |
| 24 | {
|
| 25 | m_latitude = 0.0; |
| 26 | m_longitude = 0.0; |
| 27 | } |
| 28 | |
| 29 | Spherical::Spherical(double latitude, double longitude) |
| 30 | {
|
| 31 | m_latitude = latitude; |
| 32 | m_longitude = longitude; |
| 33 | } |
| 34 | |
| 35 | Spherical::Spherical(wxString latitude, wxString longitude) |
| 36 | {
|
| 37 | latitude.ToDouble(&m_latitude); |
| 38 | longitude.ToDouble(&m_longitude); |
| 39 | } |
| 40 | |
| 41 | void Spherical::SetLatitude(double latitude) |
| 42 | {
|
| 43 | m_latitude = latitude; // TODO: error handle
|
| 44 | } |
| 45 | |
| 46 | void Spherical::SetLongitude(double longitude) |
| 47 | {
|
| 48 | m_longitude = longitude; |
| 49 | } |
| 50 | |
| 51 | double range(const Spherical &from, const Spherical &to) |
| 52 | {
|
| 53 | double lat1 = to_radians(from.m_latitude);
|
| 54 | double lon1 = to_radians(from.m_longitude);
|
| 55 | |
| 56 | double lat2 = to_radians(to.m_latitude);
|
| 57 | double lon2 = to_radians(to.m_longitude);
|
| 58 | |
| 59 | double n1 = sin((lat1-lat2)/2); |
| 60 | double n2 = sin((lon1-lon2)/2); |
| 61 | double distance = 2*asin(sqrt(n1*n1 + cos(lat1)*cos(lat2)*n2*n2)); |
| 62 | |
| 63 | return to_degrees(distance)*60.0*1.15077945; // Conversion to statute miles |
| 64 | |
| 65 | } |
| 66 | |
| 67 | double bearing(const Spherical &from, const Spherical &to) |
| 68 | {
|
| 69 | double lat1 = to_radians(from.m_latitude);
|
| 70 | double lon1 = to_radians(from.m_longitude);
|
| 71 | double lat2 = to_radians(to.m_latitude);
|
| 72 | double lon2 = to_radians(to.m_longitude);
|
| 73 | |
| 74 | double bearing = atan2(-sin(lon1-lon2)*cos(lat2), cos(lat1)*sin(lat2)-sin(lat1)*cos(lat2)*cos(lon1-lon2));
|
| 75 | return degree_normalize(to_degrees(bearing));
|
| 76 | } |