4 XCSoar Glide Computer - http://www.xcsoar.org/
5 Copyright (C) 2000-2013 The XCSoar Project
6 A detailed list of copyright holders can be found in the file "AUTHORS".
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 * @brief Library for calculating Earth dimensions
27 * This library provides general functions for calculating dimensions
28 * on the Earth with GPS coordinates.
31 #ifndef XCSOAR_GEO_MATH_HPP
32 #define XCSOAR_GEO_MATH_HPP
34 #include "Math/fixed.hpp"
35 #include "Math/Angle.hpp"
36 #include "Constants.hpp"
42 * Convert a distance on earth's surface [m] to the according Angle,
43 * assuming the earth is a sphere.
47 EarthDistanceToAngle(fixed distance
)
49 return Angle::Radians(distance
/ REARTH
);
53 * Convert an angle to the according distance on earth's surface [m],
54 * assuming the earth is a sphere.
58 AngleToEarthDistance(Angle angle
)
60 return angle
.Radians() * REARTH
;
64 * Finds cross track error in meters and closest point P4 between P3
65 * and desired track P1-P2. Very slow function!
68 CrossTrackError(const GeoPoint
&loc1
, const GeoPoint
&loc2
,
69 const GeoPoint
&loc3
, GeoPoint
*loc4
);
72 * Calculates projected distance from P3 along line P1-P2.
76 ProjectedDistance(const GeoPoint
&loc1
, const GeoPoint
&loc2
,
77 const GeoPoint
&loc3
);
80 DistanceBearing(const GeoPoint
&loc1
, const GeoPoint
&loc2
,
81 fixed
*distance
, Angle
*bearing
);
84 * Calculates the distance between two locations
85 * @param loc1 Location 1
86 * @param loc2 Location 2
87 * @return The distance
91 Distance(const GeoPoint
&loc1
, const GeoPoint
&loc2
);
94 * Calculates the bearing between two locations
95 * @param loc1 Location 1
96 * @param loc2 Location 2
101 Bearing(const GeoPoint
&loc1
, const GeoPoint
&loc2
);
104 * Finds the point along a distance dthis (m) between p1 and p2, which are
105 * separated by dtotal.
107 * This is a slow function. Adapted from The Aviation Formulary 1.42.
111 IntermediatePoint(const GeoPoint
&loc1
, const GeoPoint
&loc2
,
115 * Find the nearest great-circle middle point between the two.
119 Middle(const GeoPoint
&a
, const GeoPoint
&b
);
122 * Calculate and add distances between point 1 and 2, and point 2 and 3.
124 * @param loc1 Location 1
125 * @param loc2 Location 2
126 * @param loc3 Location 3
128 * @return Distance 12 plus 23 (m)
132 DoubleDistance(const GeoPoint
&loc1
, const GeoPoint
&loc2
,
133 const GeoPoint
&loc3
);
136 * Calculates the location (loc_out) you would have, after being at
137 * a certain start location (loc) with a certain Bearing and going straight
138 * forward for a certain Distance.
139 * @param loc Current location
140 * @param Bearing Current bearing
141 * @param Distance Distance to predict
142 * @param loc_out Future location
145 GeoPoint
FindLatitudeLongitude(const GeoPoint
&loc
,
146 const Angle bearing
, const fixed distance
);