23 #ifndef UTILS_MATH_UTILS_H_
24 #define UTILS_MATH_UTILS_H_
38 for (std::vector<double>::const_iterator it =
angles.begin(); it !=
angles.end(); ++it)
46 return std::atan2(y, x);
55 template <
typename P1,
typename P2>
58 return std::sqrt(std::pow(point2.x - point1.x, 2) + std::pow(point2.y - point1.y, 2));
62 inline double distance_points2d(
double x1,
double y1,
double x2,
double y2) {
return std::sqrt(std::pow(x2 - x1, 2) + std::pow(y2 - y1, 2)); }
70 template <
typename V1,
typename V2>
71 inline double cross2d(
const V1& v1,
const V2& v2)
73 return v1.x() * v2.y() - v2.x() * v1.y();
83 if (theta >= -M_PI && theta < M_PI)
return theta;
85 double multiplier = std::floor(theta / (2.0 * M_PI));
86 theta = theta - multiplier * 2.0 * M_PI;
87 if (theta >= M_PI) theta -= 2.0 * M_PI;
88 if (theta < -M_PI) theta += 2.0 * M_PI;
107 #endif // UTILS_MATH_UTILS_H_