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_
double interpolate_angle(double angle1, double angle2, double factor)
Return the interpolated angle between two angles [rad].
double average_angles(const std::vector< double > &angles)
Return the average angle of an arbitrary number of given angles [rad].
double distance_points2d(const P1 &point1, const P2 &point2)
Calculate Euclidean distance between two 2D point datatypes.
double normalize_theta(double theta)
normalize angle to interval [-pi, pi)
double cross2d(const V1 &v1, const V2 &v2)
Calculate the 2d cross product (returns length of the resulting vector along the z-axis in 3d) ...