Robotics Library  0.7.0
Unit.h
Go to the documentation of this file.
1 //
2 // Copyright (c) 2009, Markus Rickert
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are met:
7 //
8 // * Redistributions of source code must retain the above copyright notice,
9 // this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright notice,
11 // this list of conditions and the following disclaimer in the documentation
12 // and/or other materials provided with the distribution.
13 //
14 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
18 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 // POSSIBILITY OF SUCH DAMAGE.
25 //
26 
27 #ifndef RL_MATH_UNIT_H
28 #define RL_MATH_UNIT_H
29 
30 #include <cmath>
31 
32 #include "Real.h"
33 
34 namespace rl
35 {
36  namespace math
37  {
161  enum Unit
162  {
183  };
184 
185  static const Real DEG2RAD = static_cast<Real>(M_PI) / 180.0f;
186 
187  static const Real GIGA2UNIT = 1.0e+9f;
188 
190  static const Real GRAVITY = 9.80665f;
191 
192  static const Real KILO2UNIT = 1.0e+3f;
193 
194  static const Real MEGA2UNIT = 1.0e+6f;
195 
196  static const Real MICRO2UNIT = 1.0e-6f;
197 
198  static const Real MILLI2UNIT = 1.0e-3f;
199 
200  static const Real NANO2UNIT = 1.0e-9f;
201 
202  static const Real RAD2DEG = 180.0f / static_cast<Real>(M_PI);
203 
204  static const Real UNIT2GIGA = 1.0e-9f;
205 
206  static const Real UNIT2KILO = 1.0e-3f;
207 
208  static const Real UNIT2MEGA = 1.0e-6f;
209 
210  static const Real UNIT2MICRO = 1.0e+6f;
211 
212  static const Real UNIT2MILLI = 1.0e+3f;
213 
214  static const Real UNIT2NANO = 1.0e+9f;
215 
216  inline void cartesianToPolar(const Real& x, const Real& y, Real& r, Real& theta)
217  {
218  r = ::std::sqrt(::std::pow(x, 2) + ::std::pow(y, 2));
219  theta = ::std::atan2(y, x);
220  }
221 
222  inline void cartesianToSpherical(const Real& x, const Real& y, const Real& z, Real& rho, Real& psi, Real& theta)
223  {
224  rho = ::std::sqrt(::std::pow(x, 2) + ::std::pow(y, 2) + ::std::pow(z, 2));
225  psi = ::std::atan2(::std::sqrt(::std::pow(x, 2) + ::std::pow(y, 2)), z);
226  theta = ::std::atan2(y, x);
227  }
228 
229  inline void polarToCartesian(const Real& r, const Real& theta, Real& x, Real& y)
230  {
231  x = r * ::std::cos(theta);
232  y = r * ::std::sin(theta);
233  }
234 
235  inline void sphericalToCartesian(const Real& rho, const Real& psi, const Real& theta, Real& x, Real& y, Real& z)
236  {
237  x = rho * ::std::sin(psi) * ::std::cos(theta);
238  y = rho * ::std::sin(psi) * ::std::sin(theta);
239  z = rho * ::std::cos(psi);
240  }
241  }
242 }
243 
244 #endif // RL_MATH_UNIT_H
rl::math::UNIT_VOLT
@ UNIT_VOLT
Definition: Unit.h:174
pow
Quaternion< Scalar > pow(const Scalar &t) const
Definition: QuaternionBaseAddons.h:128
rl::math::GIGA2UNIT
static const Real GIGA2UNIT
Definition: Unit.h:187
rl::math::UNIT_NEWTON_METER
@ UNIT_NEWTON_METER
Definition: Unit.h:182
rl::math::UNIT_NONE
@ UNIT_NONE
Definition: Unit.h:163
rl::math::MILLI2UNIT
static const Real MILLI2UNIT
Definition: Unit.h:198
rl::math::UNIT_KELVIN
@ UNIT_KELVIN
Definition: Unit.h:168
rl::math::UNIT_MOLE
@ UNIT_MOLE
Definition: Unit.h:169
rl::math::UNIT_RADIAN_PER_SECOND_SQUARED
@ UNIT_RADIAN_PER_SECOND_SQUARED
Definition: Unit.h:179
rl::math::UNIT2KILO
static const Real UNIT2KILO
Definition: Unit.h:206
rl::math::UNIT_NEWTON
@ UNIT_NEWTON
Definition: Unit.h:173
rl::math::RAD2DEG
static const Real RAD2DEG
Definition: Unit.h:202
rl::math::UNIT_NEWTON_METER_SECOND
@ UNIT_NEWTON_METER_SECOND
Definition: Unit.h:181
rl::math::sphericalToCartesian
void sphericalToCartesian(const Real &rho, const Real &psi, const Real &theta, Real &x, Real &y, Real &z)
Definition: Unit.h:235
rl::math::MEGA2UNIT
static const Real MEGA2UNIT
Definition: Unit.h:194
rl::math::UNIT_AMPERE
@ UNIT_AMPERE
Definition: Unit.h:167
rl::math::DEG2RAD
static const Real DEG2RAD
Definition: Unit.h:185
rl::math::UNIT2NANO
static const Real UNIT2NANO
Definition: Unit.h:214
rl::math::UNIT2MILLI
static const Real UNIT2MILLI
Definition: Unit.h:212
rl::math::cartesianToSpherical
void cartesianToSpherical(const Real &x, const Real &y, const Real &z, Real &rho, Real &psi, Real &theta)
Definition: Unit.h:222
rl::math::UNIT_CELSIUS
@ UNIT_CELSIUS
Definition: Unit.h:175
rl::math::UNIT_RADIAN
@ UNIT_RADIAN
Definition: Unit.h:171
rl::math::UNIT_NEWTON_SECOND
@ UNIT_NEWTON_SECOND
Definition: Unit.h:180
rl::math::UNIT_CANDELA
@ UNIT_CANDELA
Definition: Unit.h:170
rl::math::Unit
Unit
Definition: Unit.h:162
rl::math::UNIT_METER_PER_SECOND_SQUARED
@ UNIT_METER_PER_SECOND_SQUARED
Definition: Unit.h:177
rl::math::polarToCartesian
void polarToCartesian(const Real &r, const Real &theta, Real &x, Real &y)
Definition: Unit.h:229
rl::math::UNIT2GIGA
static const Real UNIT2GIGA
Definition: Unit.h:204
rl::math::NANO2UNIT
static const Real NANO2UNIT
Definition: Unit.h:200
rl::math::UNIT_RADIAN_PER_SECOND
@ UNIT_RADIAN_PER_SECOND
Definition: Unit.h:178
Real.h
rl::math::UNIT_KILOGRAM
@ UNIT_KILOGRAM
Definition: Unit.h:165
rl::math::UNIT_HERTZ
@ UNIT_HERTZ
Definition: Unit.h:172
rl::math::UNIT_METER
@ UNIT_METER
Definition: Unit.h:164
rl::math::MICRO2UNIT
static const Real MICRO2UNIT
Definition: Unit.h:196
rl::math::KILO2UNIT
static const Real KILO2UNIT
Definition: Unit.h:192
rl::math::Real
double Real
Definition: Real.h:42
rl::math::GRAVITY
static const Real GRAVITY
[m ยท s-2]
Definition: Unit.h:190
rl::math::cartesianToPolar
void cartesianToPolar(const Real &x, const Real &y, Real &r, Real &theta)
Definition: Unit.h:216
rl::math::UNIT_SECOND
@ UNIT_SECOND
Definition: Unit.h:166
rl::math::UNIT2MEGA
static const Real UNIT2MEGA
Definition: Unit.h:208
rl::math::UNIT_METER_PER_SECOND
@ UNIT_METER_PER_SECOND
Definition: Unit.h:176
rl::math::UNIT2MICRO
static const Real UNIT2MICRO
Definition: Unit.h:210
rl
Robotics Library.
Definition: AnalogInput.cpp:30