DeviceDescriptor: eliminate obsolete NMEAOut kludge
[xcsoar.git] / src / Geo / Math.hpp
blob69c6bdb061d0cd5444a3e598a2683806b8e6a2db
1 /*
2 Copyright_License {
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.
24 /*! @file
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"
37 #include "Compiler.h"
39 struct GeoPoint;
41 /**
42 * Convert a distance on earth's surface [m] to the according Angle,
43 * assuming the earth is a sphere.
45 constexpr
46 static inline Angle
47 EarthDistanceToAngle(fixed distance)
49 return Angle::Radians(distance / REARTH);
52 /**
53 * Convert an angle to the according distance on earth's surface [m],
54 * assuming the earth is a sphere.
56 constexpr
57 static inline fixed
58 AngleToEarthDistance(Angle angle)
60 return angle.Radians() * REARTH;
63 /**
64 * Finds cross track error in meters and closest point P4 between P3
65 * and desired track P1-P2. Very slow function!
67 fixed
68 CrossTrackError(const GeoPoint &loc1, const GeoPoint &loc2,
69 const GeoPoint &loc3, GeoPoint *loc4);
71 /**
72 * Calculates projected distance from P3 along line P1-P2.
74 gcc_pure
75 fixed
76 ProjectedDistance(const GeoPoint &loc1, const GeoPoint &loc2,
77 const GeoPoint &loc3);
79 void
80 DistanceBearing(const GeoPoint &loc1, const GeoPoint &loc2,
81 fixed *distance, Angle *bearing);
83 /**
84 * Calculates the distance between two locations
85 * @param loc1 Location 1
86 * @param loc2 Location 2
87 * @return The distance
89 gcc_pure
90 fixed
91 Distance(const GeoPoint &loc1, const GeoPoint &loc2);
93 /**
94 * Calculates the bearing between two locations
95 * @param loc1 Location 1
96 * @param loc2 Location 2
97 * @return The bearing
99 gcc_pure
100 Angle
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.
109 gcc_pure
110 GeoPoint
111 IntermediatePoint(const GeoPoint &loc1, const GeoPoint &loc2,
112 const fixed dthis);
115 * Find the nearest great-circle middle point between the two.
117 gcc_pure
118 GeoPoint
119 Middle(const GeoPoint &a, const GeoPoint &b);
121 /**
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)
130 gcc_pure
131 fixed
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
144 gcc_pure
145 GeoPoint FindLatitudeLongitude(const GeoPoint &loc,
146 const Angle bearing, const fixed distance);
148 #endif