2 Copyright 2006 Johnathan Corgan.
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.
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.
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., 51 Franklin Street,
16 Boston, MA 02110-1301, USA.
19 // Application level includes
20 #include "spherical.h"
23 Spherical::Spherical()
29 Spherical::Spherical(double latitude, double longitude)
31 m_latitude = latitude;
32 m_longitude = longitude;
35 Spherical::Spherical(wxString latitude, wxString longitude)
37 latitude.ToDouble(&m_latitude);
38 longitude.ToDouble(&m_longitude);
41 void Spherical::SetLatitude(double latitude)
43 m_latitude = latitude; // TODO: error handle
46 void Spherical::SetLongitude(double longitude)
48 m_longitude = longitude;
51 double range(const Spherical &from, const Spherical &to)
53 double lat1 = to_radians(from.m_latitude);
54 double lon1 = to_radians(from.m_longitude);
56 double lat2 = to_radians(to.m_latitude);
57 double lon2 = to_radians(to.m_longitude);
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));
63 return to_degrees(distance)*60.0*1.15077945; // Conversion to statute miles
67 double bearing(const Spherical &from, const Spherical &to)
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);
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));