ad_physics
AngleOperation.hpp
Go to the documentation of this file.
1 // ----------------- BEGIN LICENSE BLOCK ---------------------------------
2 //
3 // Copyright (C) 2020-2021 Intel Corporation
4 //
5 // SPDX-License-Identifier: MIT
6 //
7 // ----------------- END LICENSE BLOCK -----------------------------------
8 
13 #pragma once
14 
15 #include <cmath>
16 #include "ad/physics/Types.hpp"
17 
30 {
31  v.ensureValid();
32  t.ensureValid();
33  ad::physics::Angle const s(static_cast<double>(v) * static_cast<double>(t));
34  s.ensureValid();
35  return s;
36 }
37 
50 {
51  return operator*(v, t);
52 }
53 
66 {
67  a.ensureValid();
68  t.ensureValid();
69  ad::physics::AngularVelocity const v(static_cast<double>(a) * static_cast<double>(t));
70  v.ensureValid();
71  return v;
72 }
73 
86 {
87  return operator*(a, t);
88 }
89 
93 namespace ad {
97 namespace physics {
98 
102 static const Angle cPI(M_PI);
103 
107 static const Angle c2PI(2. * M_PI);
108 
112 static const Angle cPI_2(M_PI_2);
113 
119 inline Angle normalizeAngle(Angle const &angle)
120 {
121  angle.ensureValid();
122  double normalizedAngle = std::fmod(static_cast<double>(angle), 2. * M_PI);
123  if (normalizedAngle < 0.)
124  {
125  normalizedAngle += 2. * M_PI;
126  }
127  return Angle(normalizedAngle);
128 }
129 
135 inline Angle normalizeAngleSigned(Angle const &angle)
136 {
137  angle.ensureValid();
138  double normalizedAngle = std::fmod(static_cast<double>(angle) + M_PI, 2. * M_PI);
139  if (normalizedAngle <= 0.)
140  {
141  normalizedAngle += M_PI;
142  }
143  else
144  {
145  normalizedAngle -= M_PI;
146  }
147  return Angle(normalizedAngle);
148 }
149 
150 } // namespace physics
151 } // namespace ad
152 
153 namespace std {
154 
160 inline double sin(ad::physics::Angle const &angle)
161 {
162  angle.ensureValid();
163  return sin(static_cast<double>(angle));
164 }
165 
171 inline double cos(ad::physics::Angle const &angle)
172 {
173  angle.ensureValid();
174  return cos(static_cast<double>(angle));
175 }
176 
182 inline double tan(ad::physics::Angle const &angle)
183 {
184  angle.ensureValid();
185  return tan(static_cast<double>(angle));
186 }
187 
188 } // namespace std
ad
namespace ad
Definition: Acceleration.hpp:30
std::sin
double sin(ad::physics::Angle const &angle)
Definition: AngleOperation.hpp:160
std::cos
double cos(ad::physics::Angle const &angle)
Definition: AngleOperation.hpp:171
ad::physics::Angle
DataType Angle.
Definition: Angle.hpp:59
ad::physics::c2PI
static const Angle c2PI(2. *M_PI)
constant 2*PI
ad::physics::AngularVelocity::ensureValid
void ensureValid() const
ensure that the AngularVelocity is valid
Definition: AngularVelocity.hpp:395
ad::physics::normalizeAngleSigned
Angle normalizeAngleSigned(Angle const &angle)
Definition: AngleOperation.hpp:135
ad::physics::AngularAcceleration::ensureValid
void ensureValid() const
ensure that the AngularAcceleration is valid
Definition: AngularAcceleration.hpp:396
ad::physics::Duration::ensureValid
void ensureValid() const
ensure that the Duration is valid
Definition: Duration.hpp:416
operator*
ad::physics::Angle operator*(ad::physics::AngularVelocity const &v, ad::physics::Duration const &t)
Arithmetic physics operation s = v * t.
Definition: AngleOperation.hpp:29
std::tan
double tan(ad::physics::Angle const &angle)
Definition: AngleOperation.hpp:182
ad::physics::AngularAcceleration
DataType AngularAcceleration.
Definition: AngularAcceleration.hpp:59
ad::physics::Angle::ensureValid
void ensureValid() const
ensure that the Angle is valid
Definition: Angle.hpp:394
Types.hpp
ad::physics::normalizeAngle
Angle normalizeAngle(Angle const &angle)
Definition: AngleOperation.hpp:119
ad::physics::cPI_2
static const Angle cPI_2(M_PI_2)
constant PI/2
ad::physics::Duration
DataType Duration.
Definition: Duration.hpp:67
ad::physics::AngularVelocity
DataType AngularVelocity.
Definition: AngularVelocity.hpp:59
ad::physics::cPI
static const Angle cPI(M_PI)
constant PI