title: SLERP rotates in the wrong direction (i.e. not shortest path)
body: <p>I have two ellipsoids in R3 described in terms of their centre points (P), their axes lengths (a,b,c), and their rotation vector (R). I wish to interpolate a tubular structure between these two ellipsoids along a given centre line. This is done by creating an ellipsoid centred at each point along the centre line. Its axes lengths are interpolated linearly between those at the two endpoints, and the rotation is obtained as a quaternion using spherical linear interpolation, or <a href="https://en.wikipedia.org/wiki/Slerp" rel="nofollow noreferrer">SLERP</a>.</p>
  
  <p>I previously asked a similar question on this problem <a href="https://stackoverflow.com/questions/16803721/interpolating-between-two-arbitrarily-oriented-ellipsoids">here</a>. I have since isolated the issue a little further, and thought it warranted a new post. The difference here is that before doing SLERP, I first rotate the two reference ellipsoids by the inverse of the rotation matrix that describes one of them, such that one of them is now axis-aligned (i.e. has no rotation). Previously this appeared to solve the problem, but I have encountered an example where this fix does not work.</p>
  
  <p>The source code to reproduce this issue is available <a href="http://pastebin.com/At9GAsqg" rel="nofollow noreferrer">here</a>. The relevant function is <code>ellipsoidSLERP</code> and the functions it calls. Here is a screenshot of the output:</p>
  
  <p><img src="https://i.stack.imgur.com/jnVZI.png" alt="ellipsoid SLERP"></p>
  
  <p>What you are seeing is an interpolation of ellipsoid volumes (blue) between two reference ellipsoid volumes at either end (green) along a centreline (cyan). </p>
  
  <p><strong>Problem Statement</strong></p>
  
  <p>The interpolation on the left works correctly, resulting in a smooth tubular structure. The interpolation on the right does not work correctly, and results in a twist.</p>
  
  <p>What is causing this behaviour, and how can I correct it?</p>
  
  <p>Please let me know if there's anything I can do to clarify.</p>