Choreonoid  1.8
MathUtil.h
Go to the documentation of this file.
1 #ifndef CNOID_UTIL_MATH_UTIL_H
2 #define CNOID_UTIL_MATH_UTIL_H
3 
4 #include <cmath>
5 
6 namespace cnoid {
7 
8 constexpr double PI = 3.141592653589793238462643383279502884;
9 constexpr double PI_2 = 1.570796326794896619231321691639751442;
10 constexpr double TO_DEGREE = 180.0 / PI;
11 constexpr double TO_RADIAN = PI / 180.0;
12 
13 inline double degree(double rad) { return TO_DEGREE * rad; }
14 inline double radian(double deg) { return TO_RADIAN * deg; }
15 inline float degree(float rad) { return (float)TO_DEGREE * rad; }
16 inline float radian(float deg) { return (float)TO_RADIAN * deg; }
17 inline double radian(int deg) { return TO_RADIAN * deg; }
18 
19 template<int precision>
20 double reducePrecision(double x)
21 {
22 #ifndef _MSC_VER
23  constexpr double r = std::pow(10.0, precision);
24 #else
25  const double r = std::pow(10.0, precision);
26 #endif
27  return std::nearbyint(r * x) / r;
28 }
29 
30 }
31 
32 #endif
cnoid::reducePrecision
double reducePrecision(double x)
Definition: MathUtil.h:20
cnoid::TO_DEGREE
constexpr double TO_DEGREE
Definition: MathUtil.h:10
cnoid::TO_RADIAN
constexpr double TO_RADIAN
Definition: MathUtil.h:11
cnoid::PI_2
constexpr double PI_2
Definition: MathUtil.h:9
cnoid::radian
Vector3 radian(const Vector3 &v)
Definition: EigenUtil.h:16
cnoid::PI
constexpr double PI
Definition: MathUtil.h:8
cnoid
Definition: AbstractSceneLoader.h:11
cnoid::degree
Vector3 degree(const Vector3 &v)
Definition: EigenUtil.h:15