Angle.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 
39 #include <limits>
40 #include <math.h>
41 #include "Angle.hpp"
42 #include "GNSSconstants.hpp"
43 
44 namespace gnsstk
45 {
46  Angle ::
48  : radians(std::numeric_limits<double>::quiet_NaN()),
49  degrees(std::numeric_limits<double>::quiet_NaN()),
50  tangent(std::numeric_limits<double>::quiet_NaN()),
51  semicircles(std::numeric_limits<double>::quiet_NaN())
52  {
53  }
54 
55 
56  Angle ::
57  Angle(double s, double c)
58  : AngleReduced(s,c)
59  {
60  radians = atan2(s,c);
64  }
65 
66 
67  void Angle ::
68  setValue(double v, AngleType t)
69  {
70  switch (t)
71  {
72  case AngleType::Rad:
73  radians = v;
74  degrees = v * RAD2DEG;
75  semicircles = v / PI;
76  sine = ::sin(radians);
77  cosine = ::cos(radians);
79  break;
80  case AngleType::Deg:
81  radians = v * DEG2RAD;
82  degrees = v;
83  semicircles = v / 180.0;
84  sine = ::sin(radians);
85  cosine = ::cos(radians);
87  break;
89  radians = v * PI;
90  degrees = v * 180.0;
91  semicircles = v;
92  sine = ::sin(radians);
93  cosine = ::cos(radians);
95  break;
96  case AngleType::Sin:
97  radians = asin(v);
100  sine = v;
101  cosine = ::sqrt(1-v*v);
102  tangent = ::tan(radians);
103  break;
104  case AngleType::Cos:
105  radians = acos(v);
106  degrees = radians * RAD2DEG;
107  semicircles = radians / PI;
108  sine = ::sqrt(1-v*v);
109  cosine = v;
110  tangent = ::tan(radians);
111  break;
112  default:
113  GNSSTK_THROW(Exception("Invalid type in setValue"));
114  break;
115  }
116  } // setValue
117 
118 
120  operator-(const Angle& right) const
121  {
122  double newrad = radians - right.radians;
123  Angle rv(newrad, AngleType::Rad);
124  return rv;
125  }
126 
127 
129  operator+(const Angle& right) const
130  {
131  double newrad = radians + right.radians;
132  Angle rv(newrad, AngleType::Rad);
133  return rv;
134  }
135 
136 
137  std::string Angle ::
138  asString() const
139  {
140  std::ostringstream s;
141  s << *this;
142  return s.str();
143  }
144 
145 } // namespace gnsstk
gnsstk::AngleType::SemiCircle
@ SemiCircle
Value is in semi-circles (aka half-cycles).
gnsstk::AngleReduced
Definition: AngleReduced.hpp:60
gnsstk::Angle::operator-
Angle operator-() const
Definition: Angle.hpp:85
gnsstk::DEG2RAD
const double DEG2RAD
Multiply degrees by DEG2RAD to get radians.
Definition: GNSSconstants.hpp:64
gnsstk::Angle::radians
double radians
The angle in radians.
Definition: Angle.hpp:114
gnsstk::Angle::tan
double tan() const
Get the tangent of this angle.
Definition: Angle.hpp:106
gnsstk::Angle::asString
std::string asString() const
Definition: Angle.cpp:138
gnsstk::AngleReduced::sin
double sin() const
Get the sine of this angle.
Definition: AngleReduced.hpp:94
Angle.hpp
gnsstk::Angle::Angle
Angle()
Initialize all data to NaN.
Definition: Angle.cpp:47
gnsstk::Angle::tangent
double tangent
The tangent of the angle.
Definition: Angle.hpp:116
gnsstk::PI
const double PI
GPS value of PI; also specified by GAL.
Definition: GNSSconstants.hpp:62
gnsstk::Angle::semicircles
double semicircles
The angle in semi-circles (aka half-cycles).
Definition: Angle.hpp:117
GNSSconstants.hpp
gnsstk
For Sinex::InputHistory.
Definition: BasicFramework.cpp:50
gnsstk::Angle
Definition: Angle.hpp:53
gnsstk::Exception
Definition: Exception.hpp:151
gnsstk::AngleType::Rad
@ Rad
Value is in radians.
gnsstk::RAD2DEG
const double RAD2DEG
Multiply radians by RAD2DEG to get degrees.
Definition: GNSSconstants.hpp:66
gnsstk::AngleType::Sin
@ Sin
Value is the sine of the angle.
gnsstk::AngleType::Cos
@ Cos
Value is the cosine of the angle.
gnsstk::AngleReduced::cos
double cos() const
Get the cosine of this angle.
Definition: AngleReduced.hpp:98
gnsstk::AngleType::Deg
@ Deg
Value is in degrees.
gnsstk::Angle::operator+
Angle operator+(const Angle &right) const
Definition: Angle.cpp:129
gnsstk::AngleType
AngleType
Definition: AngleType.hpp:54
gnsstk::Angle::degrees
double degrees
The angle in degrees.
Definition: Angle.hpp:115
gnsstk::AngleReduced::sine
double sine
The sine of the angle.
Definition: AngleReduced.hpp:105
gnsstk::AngleReduced::cosine
double cosine
The cosine of the angle.
Definition: AngleReduced.hpp:106
gnsstk::Angle::setValue
void setValue(double v, AngleType t)
Definition: Angle.cpp:68
std
Definition: Angle.hpp:142
GNSSTK_THROW
#define GNSSTK_THROW(exc)
Definition: Exception.hpp:366


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