sgp4/libsgp4/CoordGeodetic.h

153 lines
3.4 KiB
C
Raw Normal View History

2011-12-16 23:38:28 +00:00
#ifndef COORDGEODETIC_H_
#define COORDGEODETIC_H_
#include "Util.h"
2011-12-16 23:38:28 +00:00
#include <string>
#include <sstream>
#include <iomanip>
2012-10-11 18:52:51 +00:00
/**
* @brief Stores a geodetic location (latitude, longitude, altitude).
*
* Internally the values are stored in radians and kilometres.
2012-10-11 18:52:51 +00:00
*/
2011-12-16 23:38:28 +00:00
struct CoordGeodetic
{
public:
2012-10-11 18:52:51 +00:00
/**
* Default constructor
*/
2011-12-16 23:38:28 +00:00
CoordGeodetic()
2012-10-11 18:52:51 +00:00
: latitude(0.0),
longitude(0.0),
altitude(0.0)
2011-12-16 23:38:28 +00:00
{
}
2012-10-11 18:52:51 +00:00
/**
* Constructor
* @param[in] lat the latitude (degrees by default)
* @param[in] lon the longitude (degrees by default)
* @param[in] alt the altitude in kilometers
* @param[in] is_radians whether the latitude/longitude is in radians
2011-12-16 23:38:28 +00:00
*/
2012-10-11 18:52:51 +00:00
CoordGeodetic(
double lat,
double lon,
double alt,
bool is_radians = false)
2011-12-16 23:38:28 +00:00
{
if (is_radians)
{
latitude = lat;
longitude = lon;
}
else
{
latitude = Util::DegreesToRadians(lat);
longitude = Util::DegreesToRadians(lon);
}
altitude = alt;
2011-12-16 23:38:28 +00:00
}
2012-10-11 18:52:51 +00:00
/**
* Copy constructor
* @param[in] geo object to copy from
*/
CoordGeodetic(const CoordGeodetic& geo)
2011-12-16 23:38:28 +00:00
{
2012-10-11 18:52:51 +00:00
latitude = geo.latitude;
longitude = geo.longitude;
altitude = geo.altitude;
2011-12-16 23:38:28 +00:00
}
2012-10-11 18:52:51 +00:00
/**
* Destructor
*/
2011-12-16 23:38:28 +00:00
virtual ~CoordGeodetic()
{
}
2012-10-11 18:52:51 +00:00
/**
* Assignment operator
* @param[in] geo object to copy from
*/
CoordGeodetic& operator=(const CoordGeodetic& geo)
2011-12-16 23:38:28 +00:00
{
2012-10-11 18:52:51 +00:00
if (this != &geo)
2011-12-16 23:38:28 +00:00
{
2012-10-11 18:52:51 +00:00
latitude = geo.latitude;
longitude = geo.longitude;
altitude = geo.altitude;
2011-12-16 23:38:28 +00:00
}
return *this;
}
2012-10-11 18:52:51 +00:00
/**
* Equality operator
* @param[in] geo the object to compare with
* @returns whether the object is equal
*/
bool operator==(const CoordGeodetic& geo) const
2011-12-16 23:38:28 +00:00
{
2012-10-11 18:52:51 +00:00
return IsEqual(geo);
2011-12-16 23:38:28 +00:00
}
2012-10-11 18:52:51 +00:00
/**
* Inequality operator
* @param[in] geo the object to compare with
* @returns whether the object is not equal
*/
bool operator!=(const CoordGeodetic& geo) const
2011-12-16 23:38:28 +00:00
{
2012-10-11 18:52:51 +00:00
return !IsEqual(geo);
2011-12-16 23:38:28 +00:00
}
2012-10-11 18:52:51 +00:00
/**
* Dump this object to a string
* @returns string
*/
2011-12-16 23:38:28 +00:00
std::string ToString() const
{
std::stringstream ss;
2012-10-11 18:52:51 +00:00
ss << std::right << std::fixed << std::setprecision(3);
ss << "Lat: " << std::setw(7) << Util::RadiansToDegrees(latitude);
ss << ", Lon: " << std::setw(7) << Util::RadiansToDegrees(longitude);
2011-12-16 23:38:28 +00:00
ss << ", Alt: " << std::setw(9) << altitude;
return ss.str();
}
2012-10-11 18:52:51 +00:00
/** latitude in radians (-PI >= latitude < PI) */
2011-12-16 23:38:28 +00:00
double latitude;
2012-10-11 18:52:51 +00:00
/** latitude in radians (-PI/2 >= latitude <= PI/2) */
2011-12-16 23:38:28 +00:00
double longitude;
2012-10-11 18:52:51 +00:00
/** altitude in kilometers */
2011-12-16 23:38:28 +00:00
double altitude;
2012-10-11 18:52:51 +00:00
private:
bool IsEqual(const CoordGeodetic& geo) const
2011-12-16 23:38:28 +00:00
{
2012-10-11 18:52:51 +00:00
bool equal = false;
if (latitude == geo.latitude &&
longitude == geo.longitude &&
altitude == geo.altitude)
2011-12-16 23:38:28 +00:00
{
2012-10-11 18:52:51 +00:00
equal = false;
2011-12-16 23:38:28 +00:00
}
2012-10-11 18:52:51 +00:00
return equal;
2011-12-16 23:38:28 +00:00
}
};
/**
* Dump a Coordgeodetic to a stream
* @params[in,out] strm stream to output to
* @params[in] g the CoordGeodetic to print
*/
2011-12-16 23:38:28 +00:00
inline std::ostream& operator<<(std::ostream& strm, const CoordGeodetic& g)
{
return strm << g.ToString();
}
#endif