4 #include <simgear/constants.h>
6 // #define SG_GEOC_NATIVE_DEGREE
8 /// Class representing a geocentric location
11 /// Default constructor, initializes the instance to lat = lon = lat = 0
13 /// Initialize from a cartesian vector assumed to be in meters
14 /// Note that this conversion is relatively expensive to compute
15 SGGeoc(const SGVec3<double>& cart);
16 /// Initialize from a geodetic position
17 /// Note that this conversion is relatively expensive to compute
18 SGGeoc(const SGGeod& geod);
20 /// Factory from angular values in radians and radius in ft
21 static SGGeoc fromRadFt(double lon, double lat, double radius);
22 /// Factory from angular values in degrees and radius in ft
23 static SGGeoc fromDegFt(double lon, double lat, double radius);
24 /// Factory from angular values in radians and radius in m
25 static SGGeoc fromRadM(double lon, double lat, double radius);
26 /// Factory from angular values in degrees and radius in m
27 static SGGeoc fromDegM(double lon, double lat, double radius);
29 /// Return the geocentric longitude in radians
30 double getLongitudeRad(void) const;
31 /// Set the geocentric longitude from the argument given in radians
32 void setLongitudeRad(double lon);
34 /// Return the geocentric longitude in degrees
35 double getLongitudeDeg(void) const;
36 /// Set the geocentric longitude from the argument given in degrees
37 void setLongitudeDeg(double lon);
39 /// Return the geocentric latitude in radians
40 double getLatitudeRad(void) const;
41 /// Set the geocentric latitude from the argument given in radians
42 void setLatitudeRad(double lat);
44 /// Return the geocentric latitude in degrees
45 double getLatitudeDeg(void) const;
46 /// Set the geocentric latitude from the argument given in degrees
47 void setLatitudeDeg(double lat);
49 /// Return the geocentric radius in meters
50 double getRadiusM(void) const;
51 /// Set the geocentric radius from the argument given in meters
52 void setRadiusM(double radius);
54 /// Return the geocentric radius in feet
55 double getRadiusFt(void) const;
56 /// Set the geocentric radius from the argument given in feet
57 void setRadiusFt(double radius);
60 /// This one is private since construction is not unique if you do
61 /// not know the units of the arguments, use the factory methods for
63 SGGeoc(double lon, double lat, double radius);
65 /// The actual data, angles in degree, radius in meters
66 /// The rationale for storing the values in degrees is that most code places
67 /// in flightgear/terragear use degrees as a nativ input and output value.
68 /// The places where it makes sense to use radians is when we convert
69 /// to other representations or compute rotation matrices. But both tasks
70 /// are computionally intensive anyway and that additional 'toRadian'
71 /// conversion does not hurt too much
78 SGGeoc::SGGeoc(void) :
79 _lon(0), _lat(0), _radius(0)
84 SGGeoc::SGGeoc(double lon, double lat, double radius) :
85 _lon(lon), _lat(lat), _radius(radius)
90 SGGeoc::SGGeoc(const SGVec3<double>& cart)
92 SGGeodesy::SGCartToGeoc(cart, *this);
96 SGGeoc::SGGeoc(const SGGeod& geod)
99 SGGeodesy::SGGeodToCart(geod, cart);
100 SGGeodesy::SGCartToGeoc(cart, *this);
105 SGGeoc::fromRadFt(double lon, double lat, double radius)
107 #ifdef SG_GEOC_NATIVE_DEGREE
108 return SGGeoc(lon*SGD_RADIANS_TO_DEGREES, lat*SGD_RADIANS_TO_DEGREES,
109 radius*SG_FEET_TO_METER);
111 return SGGeoc(lon, lat, radius*SG_FEET_TO_METER);
117 SGGeoc::fromDegFt(double lon, double lat, double radius)
119 #ifdef SG_GEOC_NATIVE_DEGREE
120 return SGGeoc(lon, lat, radius*SG_FEET_TO_METER);
122 return SGGeoc(lon*SGD_DEGREES_TO_RADIANS, lat*SGD_DEGREES_TO_RADIANS,
123 radius*SG_FEET_TO_METER);
129 SGGeoc::fromRadM(double lon, double lat, double radius)
131 #ifdef SG_GEOC_NATIVE_DEGREE
132 return SGGeoc(lon*SGD_RADIANS_TO_DEGREES, lat*SGD_RADIANS_TO_DEGREES,
135 return SGGeoc(lon, lat, radius);
141 SGGeoc::fromDegM(double lon, double lat, double radius)
143 #ifdef SG_GEOC_NATIVE_DEGREE
144 return SGGeoc(lon, lat, radius);
146 return SGGeoc(lon*SGD_DEGREES_TO_RADIANS, lat*SGD_DEGREES_TO_RADIANS,
153 SGGeoc::getLongitudeRad(void) const
155 #ifdef SG_GEOC_NATIVE_DEGREE
156 return _lon*SGD_DEGREES_TO_RADIANS;
164 SGGeoc::setLongitudeRad(double lon)
166 #ifdef SG_GEOC_NATIVE_DEGREE
167 _lon = lon*SGD_RADIANS_TO_DEGREES;
175 SGGeoc::getLongitudeDeg(void) const
177 #ifdef SG_GEOC_NATIVE_DEGREE
180 return _lon*SGD_DEGREES_TO_RADIANS;
186 SGGeoc::setLongitudeDeg(double lon)
188 #ifdef SG_GEOC_NATIVE_DEGREE
191 _lon = lon*SGD_RADIANS_TO_DEGREES;
197 SGGeoc::getLatitudeRad(void) const
199 #ifdef SG_GEOC_NATIVE_DEGREE
200 return _lat*SGD_DEGREES_TO_RADIANS;
208 SGGeoc::setLatitudeRad(double lat)
210 #ifdef SG_GEOC_NATIVE_DEGREE
211 _lat = lat*SGD_RADIANS_TO_DEGREES;
219 SGGeoc::getLatitudeDeg(void) const
221 #ifdef SG_GEOC_NATIVE_DEGREE
224 return _lat*SGD_DEGREES_TO_RADIANS;
230 SGGeoc::setLatitudeDeg(double lat)
232 #ifdef SG_GEOC_NATIVE_DEGREE
235 _lat = lat*SGD_RADIANS_TO_DEGREES;
241 SGGeoc::getRadiusM(void) const
248 SGGeoc::setRadiusM(double radius)
255 SGGeoc::getRadiusFt(void) const
257 return _radius*SG_METER_TO_FEET;
262 SGGeoc::setRadiusFt(double radius)
264 _radius = radius*SG_FEET_TO_METER;
267 /// Output to an ostream
268 template<typename char_type, typename traits_type>
270 std::basic_ostream<char_type, traits_type>&
271 operator<<(std::basic_ostream<char_type, traits_type>& s, const SGGeoc& g)
273 return s << "lon = " << g.getLongitudeDeg()
274 << ", lat = " << g.getLatitudeDeg()
275 << ", radius = " << g.getRadiusM();