MayaFlux 0.5.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ angular_delta()

float MayaFlux::Kinesis::angular_delta ( float  to,
float  from 
)
inlinenoexcept

Shortest signed angular difference between two headings.

Parameters
toTarget angle in radians
fromSource angle in radians
Returns
Signed difference in (-pi, pi], wrapped correctly across the seam

Plain subtraction (to - from) is wrong whenever the pair straddles the -pi/pi boundary, e.g. from = 3.0, to = -3.0 is a small turn, not a turn of nearly 2*pi. This wraps into the shortest equivalent angle first.

Definition at line 353 of file Differential.hpp.

354{
355 float delta = to - from;
356 const float two_pi = 2.0F * std::numbers::pi_v<float>;
357 delta = std::fmod(delta + std::numbers::pi_v<float>, two_pi);
358 if (delta < 0.0F)
359 delta += two_pi;
360 return delta - std::numbers::pi_v<float>;
361}

Referenced by angular_velocity(), and total_turning().

+ Here is the caller graph for this function: