oh_my_loam/common/math/math_utils.cc

28 lines
723 B
C++
Raw Normal View History

2021-01-04 21:26:09 +08:00
#include "math_utils.h"
2020-10-16 18:08:31 +08:00
2021-01-04 21:26:09 +08:00
#include "common/log/log.h"
namespace common {
2020-10-16 18:08:31 +08:00
double NormalizeAngle(double ang) {
const double& two_pi = 2 * M_PI;
return ang - two_pi * std::floor((ang + M_PI) / two_pi);
}
2021-01-14 00:34:13 +08:00
double Degree2Rad(double degree) { return degree * M_PI / 180.0; }
double Rad2Degree(double rad) { return rad * 180.0 / M_PI; }
2020-10-18 01:14:43 +08:00
const std::vector<int> Range(int begin, int end, int step) {
ACHECK(step != 0) << "Step must non-zero";
int num = (end - begin) / step;
if (num <= 0) return {};
end = begin + step * num;
std::vector<int> seq(num);
for (int i = begin; i != end; i += step) seq[i] = i;
return seq;
}
const std::vector<int> Range(int end) { return Range(0, end, 1); }
2021-01-04 21:26:09 +08:00
} // namespace common