You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

angle_util.cpp 619 B

2 years ago
12345678910111213141516171819202122232425262728293031323334
  1. #include <cmath>
  2. #include "geo/private/util/angle_util.h"
  3. namespace ns
  4. {
  5. namespace geo
  6. {
  7. double normalize_angle(double theta)
  8. {
  9. return std::remainder(theta, 2 * c_pi());
  10. }
  11. double average_angle(double theta1, double theta2)
  12. {
  13. return normalize_angle(theta1 + normalize_angle(theta2 - theta1) / 2);
  14. }
  15. double angle_diff(double theta1, double theta2)
  16. {
  17. double norm1 = normalize_angle(theta1);
  18. double norm2 = normalize_angle(theta2);
  19. double diff = std::abs(norm1 - norm2);
  20. if (diff > c_pi())
  21. {
  22. diff = 2 * c_pi() - diff;
  23. }
  24. return diff;
  25. }
  26. } // namespace geo
  27. } // namespace ns