Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef CARTOGRAPHER_COMMON_MATH_H_
00018 #define CARTOGRAPHER_COMMON_MATH_H_
00019
00020 #include <cmath>
00021 #include <vector>
00022
00023 #include "Eigen/Core"
00024 #include "cartographer/common/port.h"
00025 #include "ceres/ceres.h"
00026
00027 namespace cartographer {
00028 namespace common {
00029
00030
00031 template <typename T>
00032 T Clamp(const T value, const T min, const T max) {
00033 if (value > max) {
00034 return max;
00035 }
00036 if (value < min) {
00037 return min;
00038 }
00039 return value;
00040 }
00041
00042
00043 template <typename T>
00044 constexpr T Power(T base, int exponent) {
00045 return (exponent != 0) ? base * Power(base, exponent - 1) : T(1);
00046 }
00047
00048
00049 template <typename T>
00050 constexpr T Pow2(T a) {
00051 return Power(a, 2);
00052 }
00053
00054
00055 constexpr double DegToRad(double deg) { return M_PI * deg / 180.; }
00056
00057
00058 constexpr double RadToDeg(double rad) { return 180. * rad / M_PI; }
00059
00060
00061 template <typename T>
00062 T NormalizeAngleDifference(T difference) {
00063 const T kPi = T(M_PI);
00064 while (difference > kPi) difference -= 2. * kPi;
00065 while (difference < -kPi) difference += 2. * kPi;
00066 return difference;
00067 }
00068
00069 template <typename T>
00070 T atan2(const Eigen::Matrix<T, 2, 1>& vector) {
00071 return ceres::atan2(vector.y(), vector.x());
00072 }
00073
00074 template <typename T>
00075 inline void QuaternionProduct(const double* const z, const T* const w,
00076 T* const zw) {
00077 zw[0] = z[0] * w[0] - z[1] * w[1] - z[2] * w[2] - z[3] * w[3];
00078 zw[1] = z[0] * w[1] + z[1] * w[0] + z[2] * w[3] - z[3] * w[2];
00079 zw[2] = z[0] * w[2] - z[1] * w[3] + z[2] * w[0] + z[3] * w[1];
00080 zw[3] = z[0] * w[3] + z[1] * w[2] - z[2] * w[1] + z[3] * w[0];
00081 }
00082
00083 }
00084 }
00085
00086 #endif // CARTOGRAPHER_COMMON_MATH_H_