Commit d58245d4 authored by Kersten Schuster's avatar Kersten Schuster

fwd_diff: atan2

parent 6f963407
......@@ -179,14 +179,14 @@ template <class T>
template <class T>
[[nodiscard]] constexpr fwd_diff<T> sin(angle_t<fwd_diff<T>> const& v)
{
auto [sa, ca] = sin_cos(radians(v.radians().value));
auto const [sa, ca] = sin_cos(radians(v.radians().value));
return {sa, v.radians().derivative * ca};
}
template <class T>
[[nodiscard]] constexpr fwd_diff<T> cos(angle_t<fwd_diff<T>> const& v)
{
auto [sa, ca] = sin_cos(radians(v.radians().value));
auto const [sa, ca] = sin_cos(radians(v.radians().value));
return {ca, -v.radians().derivative * sa};
}
......@@ -196,4 +196,13 @@ template <class T>
return angle_t<fwd_diff<T>>::from_radians({atan(v.value).radians(), v.derivative / (T(1) + pow2(v.value))});
}
template <class T>
[[nodiscard]] constexpr angle_t<fwd_diff<T>> atan2(fwd_diff<T> const& y, fwd_diff<T> const& x)
{
auto const denom = pow2(x.value) + pow2(y.value);
auto const der_y = y.derivative * x.value / denom;
auto const der_x = -x.derivative * y.value / denom;
return angle_t<fwd_diff<T>>::from_radians({atan2(y.value, x.value).radians(), 2*der_x + der_y});
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment