1 /* 2 * Copyright 2013 Daniel Warner <contact@danrw.com> 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef COORDTOPOCENTRIC_H_ 18 #define COORDTOPOCENTRIC_H_ 19 20 #include "Util.h" 21 22 #include <iomanip> 23 #include <sstream> 24 #include <string> 25 26 /** 27 * @brief Stores a topocentric location (azimuth, elevation, range and range 28 * rate). 29 * 30 * Azimuth and elevation are stored in radians. Range in kilometres. Range 31 * rate in kilometres/second. 32 */ 33 struct CoordTopocentric { 34 public: 35 /** 36 * Default constructor 37 */ CoordTopocentricCoordTopocentric38 CoordTopocentric() : azimuth(0.0), elevation(0.0), range(0.0), range_rate(0.0) 39 { 40 } 41 42 /** 43 * Constructor 44 * @param[in] az azimuth in radians 45 * @param[in] el elevation in radians 46 * @param[in] rnge range in kilometers 47 * @param[in] rnge_rate range rate in kilometers per second 48 */ CoordTopocentricCoordTopocentric49 CoordTopocentric(double az, double el, double rnge, double rnge_rate) 50 : azimuth(az), elevation(el), range(rnge), range_rate(rnge_rate) 51 { 52 } 53 54 /** 55 * Copy constructor 56 * @param[in] topo object to copy from 57 */ CoordTopocentricCoordTopocentric58 CoordTopocentric(const CoordTopocentric &topo) 59 { 60 azimuth = topo.azimuth; 61 elevation = topo.elevation; 62 range = topo.range; 63 range_rate = topo.range_rate; 64 } 65 66 /** 67 * Destructor 68 */ ~CoordTopocentricCoordTopocentric69 virtual ~CoordTopocentric() 70 { 71 } 72 73 /** 74 * Assignment operator 75 * @param[in] topo object to copy from 76 */ 77 CoordTopocentric &operator=(const CoordTopocentric &topo) 78 { 79 if (this != &topo) { 80 azimuth = topo.azimuth; 81 elevation = topo.elevation; 82 range = topo.range; 83 range_rate = topo.range_rate; 84 } 85 return *this; 86 } 87 88 /** 89 * Equality operator 90 * @param[in] topo value to check 91 * @returns whether the object is equal 92 */ 93 bool operator==(const CoordTopocentric &topo) const 94 { 95 return IsEqual(topo); 96 } 97 98 /** 99 * Inequality operator 100 * @param[in] topo the object to compare with 101 * @returns whether the object is not equal 102 */ 103 bool operator!=(const CoordTopocentric &topo) const 104 { 105 return !IsEqual(topo); 106 } 107 108 /** 109 * Dump this object to a string 110 * @returns string 111 */ ToStringCoordTopocentric112 std::string ToString() const 113 { 114 std::stringstream ss; 115 ss << std::right << std::fixed << std::setprecision(3); 116 ss << "Az: " << std::setw(8) << Util::RadiansToDegrees(azimuth); 117 ss << ", El: " << std::setw(8) << Util::RadiansToDegrees(elevation); 118 ss << ", Rng: " << std::setw(10) << range; 119 ss << ", Rng Rt: " << std::setw(7) << range_rate; 120 return ss.str(); 121 } 122 123 /** azimuth in radians */ 124 double azimuth; 125 /** elevations in radians */ 126 double elevation; 127 /** range in kilometers */ 128 double range; 129 /** range rate in kilometers per second */ 130 double range_rate; 131 132 private: IsEqualCoordTopocentric133 bool IsEqual(const CoordTopocentric &topo) const 134 { 135 bool equal = false; 136 if (azimuth == topo.azimuth && elevation == topo.elevation && range == topo.range 137 && range_rate == topo.range_rate) { 138 equal = true; 139 } 140 return equal; 141 } 142 }; 143 144 inline std::ostream &operator<<(std::ostream &strm, const CoordTopocentric &t) 145 { 146 return strm << t.ToString(); 147 } 148 149 #endif 150