Triple.cpp
Go to the documentation of this file.
1 //==============================================================================
2 //
3 // This file is part of GNSSTk, the ARL:UT GNSS Toolkit.
4 //
5 // The GNSSTk is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published
7 // by the Free Software Foundation; either version 3.0 of the License, or
8 // any later version.
9 //
10 // The GNSSTk is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with GNSSTk; if not, write to the Free Software Foundation,
17 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
18 //
19 // This software was developed by Applied Research Laboratories at the
20 // University of Texas at Austin.
21 // Copyright 2004-2022, The Board of Regents of The University of Texas System
22 //
23 //==============================================================================
24 
25 //==============================================================================
26 //
27 // This software was developed by Applied Research Laboratories at the
28 // University of Texas at Austin, under contract to an agency or agencies
29 // within the U.S. Department of Defense. The U.S. Government retains all
30 // rights to use, duplicate, distribute, disclose, or release this software.
31 //
32 // Pursuant to DoD Directive 523024
33 //
34 // DISTRIBUTION STATEMENT A: This software has been approved for public
35 // release, distribution is unlimited.
36 //
37 //==============================================================================
38 
44 #include "GNSSconstants.hpp"
45 #include "Triple.hpp"
46 #include <cmath>
47 
48 namespace gnsstk
49 {
50  using namespace std;
51 
53  : theArray(0., 3)
54  {
55  }
56 
57  Triple :: Triple(const Triple& right)
58  : theArray(right.theArray)
59  {
60  }
61 
62  Triple :: Triple(double a,
63  double b,
64  double c)
65  : theArray(3)
66  {
67  theArray[0] = a;
68  theArray[1] = b;
69  theArray[2] = c;
70  }
71 
73  {
74  theArray = right.theArray;
75  return *this;
76  }
77 
78  Triple& Triple :: operator=(const std::valarray<double>& right)
79  {
80  if (right.size() != 3)
81  {
82  GNSSTK_THROW(GeometryException("Incorrect vector size"));
83  }
84 
85  theArray = right;
86  return *this;
87  }
88 
89  // Return the data as a Vector<double> object
91  {
92  Vector<double> toReturn(3,0.0);
93  for(int i=0;i<3;i++) toReturn(i) = theArray[i];
94  return toReturn;
95  }
96 
97 
98  // Return the data as a std::vector object
99  std::vector<double> Triple::toStdVector()
100  {
101  std::vector<double> toReturn;
102  for(int i=0;i<3;i++) toReturn.push_back(theArray[i]);
103  return toReturn;
104  }
105 
106  // returns the dot product of the two vectors
107  double Triple :: dot(const Triple& right) const
108  noexcept
109  {
110  Triple z;
111  z = (this->theArray)*(right.theArray);
112  double a = z.theArray.sum();
113  return a;
114  }
115 
116 
117  // retuns v1 x v2 , vector cross product
118  Triple Triple :: cross(const Triple& right) const
119  noexcept
120  {
121  Triple cp;
122  cp[0] = (*this)[1] * right[2] - (*this)[2] * right[1];
123  cp[1] = (*this)[2] * right[0] - (*this)[0] * right[2];
124  cp[2] = (*this)[0] * right[1] - (*this)[1] * right[0];
125  return cp;
126  }
127 
128 
129  double Triple :: mag() const noexcept
130  {
131  return std::sqrt(dot(*this));
132  }
133 
135  {
136  double mag = std::sqrt(dot(*this));
137 
138  if (mag <= 1e-14)
139  GNSSTK_THROW(GeometryException("Divide by Zero Error"));
140 
141  Triple retArg;
142  retArg[0] = (*this)[0] / mag;
143  retArg[1] = (*this)[1] / mag;
144  retArg[2] = (*this)[2] / mag;
145  return(retArg);
146  }
147 
148  // function that returns the cosine of angle between this and right
149  double Triple :: cosVector(const Triple& right) const
150  {
151  double rx, ry, cosvects;
152 
153  rx = dot(*this);
154  ry = right.dot(right);
155 
156  if (rx <= 1e-14 || ry <= 1e-14)
157  {
158  GNSSTK_THROW(GeometryException("Divide by Zero Error"));
159  }
160  cosvects = dot(right) / ::sqrt(rx * ry);
161 
162  /* this if checks for and corrects round off error */
163  if (fabs(cosvects) > 1.0e0)
164  {
165  cosvects = fabs(cosvects) / cosvects;
166  }
167 
168  return cosvects;
169  }
170 
171 
172  // Computes the slant range between two vectors
173  double Triple :: slantRange(const Triple& right) const
174  noexcept
175  {
176  Triple z;
177  z = right.theArray - this->theArray;
178  double r = z.mag();
179  return r;
180  }
181 
182 
183  // Finds the elevation angle of the second point with respect to
184  // the first point
185  double Triple :: elvAngle(const Triple& right) const
186  {
187  Triple z;
188  z = right.theArray - this->theArray;
189  double c = z.cosVector(*this);
190  return 90.0 - ::acos(c) * RAD_TO_DEG;
191  }
192 
193 
194  // Calculates a satellites azimuth from a station
195  double Triple :: azAngle(const Triple& right) const
196  {
197  double xy, xyz, cosl, sinl, sint, xn1, xn2, xn3, xe1, xe2;
198  double z1, z2, z3, p1, p2, test, alpha;
199 
200  xy = (*this)[0] * (*this)[0] + (*this)[1] * (*this)[1] ;
201  xyz = xy + (*this)[2] * (*this)[2] ;
202  xy = ::sqrt(xy);
203  xyz = ::sqrt(xyz);
204 
205  if (xy <= 1e-14 || xyz <=1e-14)
206  GNSSTK_THROW(GeometryException("Divide by Zero Error"))
207 
208  cosl = (*this)[0] / xy;
209  sinl = (*this)[1] / xy;
210  sint = (*this)[2] / xyz;
211 
212  xn1 = -sint * cosl;
213  xn2 = -sint * sinl;
214  xn3 = xy/xyz;
215 
216  xe1 = -sinl;
217  xe2 = cosl;
218 
219  z1 = right[0] - (*this)[0];
220  z2 = right[1] - (*this)[1];
221  z3 = right[2] - (*this)[2];
222 
223  p1 = (xn1 * z1) + (xn2 * z2) + (xn3 * z3) ;
224  p2 = (xe1 * z1) + (xe2 * z2) ;
225 
226  test = fabs(p1) + fabs(p2);
227 
228  if (test < 1.0e-14)
229  {
230  GNSSTK_THROW(GeometryException("azAngle(), failed p1+p2 test."));
231  }
232 
233  alpha = 90 - ::atan2(p1, p2) * RAD_TO_DEG;
234  if (alpha < 0)
235  {
236  return alpha + 360;
237  }
238  else
239  {
240  return alpha;
241  }
242  }
243 
244 
245  /* Computes rotation about axis X.
246  * @param angle Angle to rotate, in degrees
247  * @return A triple which is the original triple rotated angle about X
248  */
249  Triple Triple::R1(const double& angle) const
250  noexcept
251  {
252  double ang(angle*DEG_TO_RAD);
253  double sinangle(std::sin(ang));
254  double cosangle(std::cos(ang));
255  Triple rot;
256  rot[0] = (*this)[0];
257  rot[1] = cosangle*(*this)[1] + sinangle*(*this)[2];
258  rot[2] = -sinangle*(*this)[1] + cosangle*(*this)[2];
259  return rot;
260  }
261 
262 
263  /* Computes rotation about axis Y.
264  * @param angle Angle to rotate, in degrees
265  * @return A triple which is the original triple rotated angle about Y
266  */
267  Triple Triple::R2(const double& angle) const
268  noexcept
269  {
270  double ang(angle*DEG_TO_RAD);
271  double sinangle(std::sin(ang));
272  double cosangle(std::cos(ang));
273  Triple rot;
274  rot[0] = cosangle*(*this)[0] - sinangle*(*this)[2];
275  rot[1] = (*this)[1];
276  rot[2] = sinangle*(*this)[0] + cosangle*(*this)[2];
277  return rot;
278  }
279 
280 
281  /* Computes rotation about axis Z.
282  * @param angle Angle to rotate, in degrees
283  * @return A triple which is the original triple rotated angle about Z
284  */
285  Triple Triple::R3(const double& angle) const
286  noexcept
287  {
288  double ang(angle*DEG_TO_RAD);
289  double sinangle(std::sin(ang));
290  double cosangle(std::cos(ang));
291  Triple rot;
292  rot[0] = cosangle*(*this)[0] + sinangle*(*this)[1];
293  rot[1] = -sinangle*(*this)[0] + cosangle*(*this)[1];
294  rot[2] = (*this)[2];
295  return rot;
296  }
297 
298 
299  bool Triple :: operator== (const Triple& right) const
300  {
301  return (*this)[0]==right[0] && (*this)[1]==right[1] && (*this)[2]==right[2];
302  }
303 
304  Triple Triple :: operator-(const Triple& right) const
305  {
306  Triple tmp;
307  tmp.theArray = this->theArray - right.theArray;
308  return tmp;
309  }
310 
311  Triple Triple :: operator+(const Triple& right) const
312  {
313  Triple tmp;
314  tmp.theArray = this->theArray + right.theArray;
315  return tmp;
316  }
317 
318  Triple operator*(double scale, const Triple& rhs)
319  {
320  Triple tmp;
321  tmp.theArray = rhs.theArray * scale;
322  return tmp;
323  }
324 
325  std::ostream& operator<<(std::ostream& s,
326  const gnsstk::Triple& v)
327  {
328  if (v.size() > 0)
329  {
330  s << "(" << v[0];
331  for (size_t i = 1; i < v.size(); i++)
332  {
333  s << ", " << v[i];
334  }
335  s << ")";
336  }
337 
338  return s;
339  }
340 
341 } // namespace gnsstk
gnsstk::Triple::toVector
Vector< double > toVector()
Return the data as a Vector<double> object.
Definition: Triple.cpp:90
gnsstk::Triple::operator+
Triple operator+(const Triple &right) const
Definition: Triple.cpp:311
gnsstk::Triple::Triple
Triple()
Default constructor, initialize as triple.
Definition: Triple.cpp:52
gnsstk::Triple::size
size_t size(void) const
Return the size of this object.
Definition: Triple.hpp:240
const
#define const
Definition: getopt.c:43
gnsstk::Triple::operator-
Triple operator-(const Triple &right) const
Definition: Triple.cpp:304
gnsstk::Triple::operator==
bool operator==(const Triple &right) const
Definition: Triple.cpp:299
gnsstk::Triple::theArray
std::valarray< double > theArray
Definition: Triple.hpp:251
GNSSconstants.hpp
gnsstk::Triple
Definition: Triple.hpp:68
gnsstk::Triple::R1
Triple R1(const double &angle) const noexcept
Definition: Triple.cpp:249
gnsstk
For Sinex::InputHistory.
Definition: BasicFramework.cpp:50
gnsstk::Triple::unitVector
Triple unitVector() const
Definition: Triple.cpp:134
std::sin
double sin(gnsstk::Angle x)
Definition: Angle.hpp:144
gnsstk::Triple::dot
double dot(const Triple &right) const noexcept
Definition: Triple.cpp:107
gnsstk::RAD_TO_DEG
static const double RAD_TO_DEG
Conversion Factor from radians to degrees (units: degrees)
Definition: GNSSconstants.hpp:78
gnsstk::operator*
SparseMatrix< T > operator*(const SparseMatrix< T > &L, const SparseMatrix< T > &R)
Matrix multiply: SparseMatrix = SparseMatrix * SparseMatrix.
Definition: SparseMatrix.hpp:1186
gnsstk::Triple::cosVector
double cosVector(const Triple &right) const
Definition: Triple.cpp:149
gnsstk::Triple::R3
Triple R3(const double &angle) const noexcept
Definition: Triple.cpp:285
gnsstk::operator<<
std::ostream & operator<<(std::ostream &s, const ObsEpoch &oe) noexcept
Definition: ObsEpochMap.cpp:54
gnsstk::Triple::operator=
Triple & operator=(const Triple &right)
Assignment operator.
Definition: Triple.cpp:72
std::cos
double cos(gnsstk::Angle x)
Definition: Angle.hpp:146
gnsstk::Vector< double >
cp
double cp
longitude sin, T*sin, cos coefficients
Definition: IERS2003NutationData.hpp:47
std
Definition: Angle.hpp:142
gnsstk::Triple::cross
Triple cross(const Triple &right) const noexcept
Definition: Triple.cpp:118
gnsstk::Triple::slantRange
double slantRange(const Triple &right) const noexcept
Definition: Triple.cpp:173
Triple.hpp
gnsstk::Triple::toStdVector
std::vector< double > toStdVector()
Return the data as a std::vector object.
Definition: Triple.cpp:99
GNSSTK_THROW
#define GNSSTK_THROW(exc)
Definition: Exception.hpp:366
gnsstk::Triple::elvAngle
double elvAngle(const Triple &right) const
Definition: Triple.cpp:185
gnsstk::Triple::azAngle
double azAngle(const Triple &right) const
Definition: Triple.cpp:195
gnsstk::Triple::R2
Triple R2(const double &angle) const noexcept
Definition: Triple.cpp:267
gnsstk::DEG_TO_RAD
static const double DEG_TO_RAD
Conversion Factor from degrees to radians (units: degrees^-1)
Definition: GNSSconstants.hpp:76
gnsstk::Triple::mag
double mag() const noexcept
Definition: Triple.cpp:129


gnsstk
Author(s):
autogenerated on Wed Oct 25 2023 02:40:42