Add geom::angle_difference

This commit is contained in:
Nikita Lisitsa 2021-03-11 21:34:03 +03:00
parent 7b84cb0b1f
commit c835925ca7

View file

@ -104,4 +104,18 @@ namespace psemek::geom
return std::pair{x1, x2};
}
template <typename T>
T angle_difference(T a0, T a1)
{
T const x0 = std::cos(a0);
T const x1 = std::cos(a1);
T const y0 = std::sin(a0);
T const y1 = std::sin(a1);
T const x = x0 * x1 + y0 * y1;
T const y = x0 * y1 - y0 * x1;
return std::atan2(y, x);
}
}