35 #ifndef GEOMETRY_ANGLES_UTILS_H 36 #define GEOMETRY_ANGLES_UTILS_H 50 return degrees * M_PI / 180.0;
58 return radians * 180.0 / M_PI;
70 return fmod(fmod(angle, 2.0*M_PI) + 2.0*M_PI, 2.0*M_PI);
119 if (angle > 2*M_PI || angle < -2.0*M_PI)
120 angle = fmod(angle, 2.0*M_PI);
122 return (2*M_PI+angle);
124 return (-2*M_PI+angle);
140 static bool find_min_max_delta(
double from,
double left_limit,
double right_limit,
double &result_min_delta,
double &result_max_delta)
152 result_min_delta = delta[0];
153 result_max_delta = std::max<double>(delta[1],delta[3]);
159 result_max_delta = delta[1];
160 result_min_delta = std::min<double>(delta[0],delta[2]);
165 double delta_min = delta[0];
166 double delta_min_2pi = delta[2];
167 if(delta[2] < delta_min)
169 delta_min = delta[2];
170 delta_min_2pi = delta[0];
173 double delta_max = delta[1];
174 double delta_max_2pi = delta[3];
175 if(delta[3] > delta_max)
177 delta_max = delta[3];
178 delta_max_2pi = delta[1];
183 if((delta_min <= delta_max_2pi) || (delta_max >= delta_min_2pi))
185 result_min_delta = delta_max_2pi;
186 result_max_delta = delta_min_2pi;
187 if(left_limit == -M_PI && right_limit == M_PI)
192 result_min_delta = delta_min;
193 result_max_delta = delta_max;
218 double min_delta = -2*M_PI;
219 double max_delta = 2*M_PI;
220 double min_delta_to = -2*M_PI;
221 double max_delta_to = 2*M_PI;
229 if(delta >= min_delta && delta <= max_delta)
231 shortest_angle = delta;
234 else if(delta_mod_2pi >= min_delta && delta_mod_2pi <= max_delta)
236 shortest_angle = delta_mod_2pi;
242 if(fabs(min_delta_to) < fabs(max_delta_to))
243 shortest_angle = std::max<double>(delta,delta_mod_2pi);
244 else if(fabs(min_delta_to) > fabs(max_delta_to))
245 shortest_angle = std::min<double>(delta,delta_mod_2pi);
248 if (fabs(delta) < fabs(delta_mod_2pi))
249 shortest_angle = delta;
251 shortest_angle = delta_mod_2pi;
260 if(fabs(min_delta) < fabs(max_delta))
261 shortest_angle = std::min<double>(delta,delta_mod_2pi);
262 else if (fabs(min_delta) > fabs(max_delta))
263 shortest_angle = std::max<double>(delta,delta_mod_2pi);
266 if (fabs(delta) < fabs(delta_mod_2pi))
267 shortest_angle = delta;
269 shortest_angle = delta_mod_2pi;
274 shortest_angle = delta;
static bool shortest_angular_distance_with_limits(double from, double to, double left_limit, double right_limit, double &shortest_angle)
Returns the delta from "from_angle" to "to_angle" making sure it does not violate limits specified by...
static double shortest_angular_distance(double from, double to)
shortest_angular_distance
static double normalize_angle(double angle)
normalize
static double normalize_angle_positive(double angle)
normalize_angle_positive
static double from_degrees(double degrees)
Convert degrees to radians.
static double two_pi_complement(double angle)
returns the angle in [-2*M_PI, 2*M_PI] going the other way along the unit circle. ...
static double to_degrees(double radians)
Convert radians to degrees.
static bool find_min_max_delta(double from, double left_limit, double right_limit, double &result_min_delta, double &result_max_delta)
This function is only intended for internal use and not intended for external use. If you do use it, read the documentation very carefully. Returns the min and max amount (in radians) that can be moved from "from" angle to "left_limit" and "right_limit".