title: Interpolate angles a 2D space over time without relying on a fixed time step
body: <p><strong>The Problem</strong></p>
  
  <p>How would one interpolate between two given angles, given a certain time delta, so that the simulated motion from rotation A or rotation B would take a similar amount of time when the algorithm is ran at different frequencies (without a fixed time step dependency).</p>
  
  <p><img src="https://i.stack.imgur.com/vCEwr.png" alt="Diagram"></p>
  
  <p><strong>Potential Solution</strong> </p>
  
  <p>I have been using the following C# code to do this kind of interpolation between two points. It solves the differential for the situation:</p>
  
  <pre><code>Vector3 SmoothLerpVector3(Vector3 x0, Vector3 y0, Vector3 yt, double t, float k)
  {
      // x0 = current position
      // y0 = last target position
      // yt = current target position
      // t = time delta between last and current target positions
      // k = damping
  
      Vector3 value = x0;
  
      if (t &gt; 0)
      {
          Vector3 f = x0 - y0 + (yt - y0) / (k * (float)t);
          value = yt - (yt - y0) / (k * (float)t) + f * (float)Math.Exp(-k * t);
      }
  
      return value;            
  }
  </code></pre>
  
  <p>This code is usable for 2D coordinates by having the <code>Z</code> coordinate of the <code>Vector3</code> set as 0.</p>
  
  <p>The "last" and "current" positions are because the target can move during the interpolation. Not taking this in to account causes motion jitter at moderately high speeds.</p>
  
  <p>I did not write this code and it appears to work. I had trouble altering this for angles because, for example, an interpolation between the angles 350° and 10° would take the 'long' way round instead of going in the direction of the 20° difference in angle. </p>
  
  <p>I've looked into quaternion slerp but haven't been able to find an implementation that takes a time delta into account. Something that I have thought of, but not been able to implement either, is to interpolate between both angles twice, but the second time with a phase difference of 180° on each angle and to output the smaller of the two multiplied by -1.</p>
  
  <p>Would appreciate any help or direction!</p>