]> git.mxchange.org Git - simgear.git/blob - simgear/math/SGGeod.hxx
Remove deprecated, now unused functions.
[simgear.git] / simgear / math / SGGeod.hxx
1 // Copyright (C) 2006  Mathias Froehlich - Mathias.Froehlich@web.de
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Library General Public
5 // License as published by the Free Software Foundation; either
6 // version 2 of the License, or (at your option) any later version.
7 //
8 // This library 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 GNU
11 // Library General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
16 //
17
18 #ifndef SGGeod_H
19 #define SGGeod_H
20
21 #include <simgear/constants.h>
22
23 // #define SG_GEOD_NATIVE_DEGREE
24
25 /// Class representing a geodetic location
26 class SGGeod {
27 public:
28   /// Default constructor, initializes the instance to lat = lon = elev = 0
29   SGGeod(void);
30
31   /// Factory from angular values in radians and elevation is 0
32   static SGGeod fromRad(double lon, double lat);
33   /// Factory from angular values in degrees and elevation is 0
34   static SGGeod fromDeg(double lon, double lat);
35   /// Factory from angular values in radians and elevation in ft
36   static SGGeod fromRadFt(double lon, double lat, double elevation);
37   /// Factory from angular values in degrees and elevation in ft
38   static SGGeod fromDegFt(double lon, double lat, double elevation);
39   /// Factory from angular values in radians and elevation in m
40   static SGGeod fromRadM(double lon, double lat, double elevation);
41   /// Factory from angular values in degrees and elevation in m
42   static SGGeod fromDegM(double lon, double lat, double elevation);
43   /// Factory to convert position from a cartesian position assumed to be
44   /// in wgs84 measured in meters
45   /// Note that this conversion is relatively expensive to compute
46   static SGGeod fromCart(const SGVec3<double>& cart);
47   /// Factory to convert position from a geocentric position
48   /// Note that this conversion is relatively expensive to compute
49   static SGGeod fromGeoc(const SGGeoc& geoc);
50
51   /// Return the geodetic longitude in radians
52   double getLongitudeRad(void) const;
53   /// Set the geodetic longitude from the argument given in radians
54   void setLongitudeRad(double lon);
55
56   /// Return the geodetic longitude in degrees
57   double getLongitudeDeg(void) const;
58   /// Set the geodetic longitude from the argument given in degrees
59   void setLongitudeDeg(double lon);
60
61   /// Return the geodetic latitude in radians
62   double getLatitudeRad(void) const;
63   /// Set the geodetic latitude from the argument given in radians
64   void setLatitudeRad(double lat);
65
66   /// Return the geodetic latitude in degrees
67   double getLatitudeDeg(void) const;
68   /// Set the geodetic latitude from the argument given in degrees
69   void setLatitudeDeg(double lat);
70
71   /// Return the geodetic elevation in meters
72   double getElevationM(void) const;
73   /// Set the geodetic elevation from the argument given in meters
74   void setElevationM(double elevation);
75
76   /// Return the geodetic elevation in feet
77   double getElevationFt(void) const;
78   /// Set the geodetic elevation from the argument given in feet
79   void setElevationFt(double elevation);
80
81 private:
82   /// This one is private since construction is not unique if you do
83   /// not know the units of the arguments. Use the factory methods for
84   /// that purpose
85   SGGeod(double lon, double lat, double elevation);
86
87   /// The actual data, angles in degree, elevation in meters
88   /// The rationale for storing the values in degrees is that most code places
89   /// in flightgear/terragear use degrees as a nativ input and output value.
90   /// The places where it makes sense to use radians is when we convert
91   /// to other representations or compute rotation matrices. But both tasks
92   /// are computionally intensive anyway and that additional 'toRadian'
93   /// conversion does not hurt too much
94   double _lon;
95   double _lat;
96   double _elevation;
97 };
98
99 inline
100 SGGeod::SGGeod(void) :
101   _lon(0), _lat(0), _elevation(0)
102 {
103 }
104
105 inline
106 SGGeod::SGGeod(double lon, double lat, double elevation) :
107   _lon(lon), _lat(lat), _elevation(elevation)
108 {
109 }
110
111 inline
112 SGGeod
113 SGGeod::fromRad(double lon, double lat)
114 {
115 #ifdef SG_GEOD_NATIVE_DEGREE
116   return SGGeod(lon*SGD_RADIANS_TO_DEGREES, lat*SGD_RADIANS_TO_DEGREES, 0);
117 #else
118   return SGGeod(lon, lat, 0);
119 #endif
120 }
121
122 inline
123 SGGeod
124 SGGeod::fromDeg(double lon, double lat)
125 {
126 #ifdef SG_GEOD_NATIVE_DEGREE
127   return SGGeod(lon, lat, 0);
128 #else
129   return SGGeod(lon*SGD_DEGREES_TO_RADIANS, lat*SGD_DEGREES_TO_RADIANS, 0);
130 #endif
131 }
132
133 inline
134 SGGeod
135 SGGeod::fromRadFt(double lon, double lat, double elevation)
136 {
137 #ifdef SG_GEOD_NATIVE_DEGREE
138   return SGGeod(lon*SGD_RADIANS_TO_DEGREES, lat*SGD_RADIANS_TO_DEGREES,
139                 elevation*SG_FEET_TO_METER);
140 #else
141   return SGGeod(lon, lat, elevation*SG_FEET_TO_METER);
142 #endif
143 }
144
145 inline
146 SGGeod
147 SGGeod::fromDegFt(double lon, double lat, double elevation)
148 {
149 #ifdef SG_GEOD_NATIVE_DEGREE
150   return SGGeod(lon, lat, elevation*SG_FEET_TO_METER);
151 #else
152   return SGGeod(lon*SGD_DEGREES_TO_RADIANS, lat*SGD_DEGREES_TO_RADIANS,
153                 elevation*SG_FEET_TO_METER);
154 #endif
155 }
156
157 inline
158 SGGeod
159 SGGeod::fromRadM(double lon, double lat, double elevation)
160 {
161 #ifdef SG_GEOD_NATIVE_DEGREE
162   return SGGeod(lon*SGD_RADIANS_TO_DEGREES, lat*SGD_RADIANS_TO_DEGREES,
163                 elevation);
164 #else
165   return SGGeod(lon, lat, elevation);
166 #endif
167 }
168
169 inline
170 SGGeod
171 SGGeod::fromDegM(double lon, double lat, double elevation)
172 {
173 #ifdef SG_GEOD_NATIVE_DEGREE
174   return SGGeod(lon, lat, elevation);
175 #else
176   return SGGeod(lon*SGD_DEGREES_TO_RADIANS, lat*SGD_DEGREES_TO_RADIANS,
177                 elevation);
178 #endif
179 }
180
181 inline
182 SGGeod
183 SGGeod::fromCart(const SGVec3<double>& cart)
184 {
185   SGGeod geod;
186   SGGeodesy::SGCartToGeod(cart, geod);
187   return geod;
188 }
189
190 inline
191 SGGeod
192 SGGeod::fromGeoc(const SGGeoc& geoc)
193 {
194   SGVec3<double> cart;
195   SGGeodesy::SGGeocToCart(geoc, cart);
196   SGGeod geod;
197   SGGeodesy::SGCartToGeod(cart, geod);
198   return geod;
199 }
200
201 inline
202 double
203 SGGeod::getLongitudeRad(void) const
204 {
205 #ifdef SG_GEOD_NATIVE_DEGREE
206   return _lon*SGD_DEGREES_TO_RADIANS;
207 #else
208   return _lon;
209 #endif
210 }
211
212 inline
213 void
214 SGGeod::setLongitudeRad(double lon)
215 {
216 #ifdef SG_GEOD_NATIVE_DEGREE
217   _lon = lon*SGD_RADIANS_TO_DEGREES;
218 #else
219   _lon = lon;
220 #endif
221 }
222
223 inline
224 double
225 SGGeod::getLongitudeDeg(void) const
226 {
227 #ifdef SG_GEOD_NATIVE_DEGREE
228   return _lon;
229 #else
230   return _lon*SGD_RADIANS_TO_DEGREES;
231 #endif
232 }
233
234 inline
235 void
236 SGGeod::setLongitudeDeg(double lon)
237 {
238 #ifdef SG_GEOD_NATIVE_DEGREE
239   _lon = lon;
240 #else
241   _lon = lon*SGD_DEGREES_TO_RADIANS;
242 #endif
243 }
244
245 inline
246 double
247 SGGeod::getLatitudeRad(void) const
248 {
249 #ifdef SG_GEOD_NATIVE_DEGREE
250   return _lat*SGD_DEGREES_TO_RADIANS;
251 #else
252   return _lat;
253 #endif
254 }
255
256 inline
257 void
258 SGGeod::setLatitudeRad(double lat)
259 {
260 #ifdef SG_GEOD_NATIVE_DEGREE
261   _lat = lat*SGD_RADIANS_TO_DEGREES;
262 #else
263   _lat = lat;
264 #endif
265 }
266
267 inline
268 double
269 SGGeod::getLatitudeDeg(void) const
270 {
271 #ifdef SG_GEOD_NATIVE_DEGREE
272   return _lat;
273 #else
274   return _lat*SGD_RADIANS_TO_DEGREES;
275 #endif
276 }
277
278 inline
279 void
280 SGGeod::setLatitudeDeg(double lat)
281 {
282 #ifdef SG_GEOD_NATIVE_DEGREE
283   _lat = lat;
284 #else
285   _lat = lat*SGD_DEGREES_TO_RADIANS;
286 #endif
287 }
288
289 inline
290 double
291 SGGeod::getElevationM(void) const
292 {
293   return _elevation;
294 }
295
296 inline
297 void
298 SGGeod::setElevationM(double elevation)
299 {
300   _elevation = elevation;
301 }
302
303 inline
304 double
305 SGGeod::getElevationFt(void) const
306 {
307   return _elevation*SG_METER_TO_FEET;
308 }
309
310 inline
311 void
312 SGGeod::setElevationFt(double elevation)
313 {
314   _elevation = elevation*SG_FEET_TO_METER;
315 }
316
317 /// Output to an ostream
318 template<typename char_type, typename traits_type>
319 inline
320 std::basic_ostream<char_type, traits_type>&
321 operator<<(std::basic_ostream<char_type, traits_type>& s, const SGGeod& g)
322 {
323   return s << "lon = " << g.getLongitudeDeg()
324            << "deg, lat = " << g.getLatitudeDeg()
325            << "deg, elev = " << g.getElevationM()
326            << "m";
327 }
328
329 #endif