oh_my_loam/common/math/math_utils.cc

34 lines
732 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) {
2021-01-22 16:33:55 +08:00
const double &two_pi = 2 * M_PI;
2020-10-16 18:08:31 +08:00
return ang - two_pi * std::floor((ang + M_PI) / two_pi);
}
2021-01-22 16:33:55 +08:00
double Degree2Rad(double degree) {
return degree * M_PI / 180.0;
}
2021-01-14 00:34:13 +08:00
2021-01-22 16:33:55 +08:00
double Rad2Degree(double rad) {
return rad * 180.0 / M_PI;
}
2021-01-14 00:34:13 +08:00
2020-10-18 01:14:43 +08:00
const std::vector<int> Range(int begin, int end, int step) {
2021-01-23 22:11:08 +08:00
ACHECK(step != 0) << "Step must be non-zero";
2020-10-18 01:14:43 +08:00
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;
}
2021-01-22 16:33:55 +08:00
const std::vector<int> Range(int end) {
return Range(0, end, 1);
}
2020-10-18 01:14:43 +08:00
2021-01-04 21:26:09 +08:00
} // namespace common