title: How to find correct rotation from one vector to another?
body: <p>I have two objects, and each object has two vectors:</p>
  
  <ul>
  <li>normal vector</li>
  <li>up vector</li>
  </ul>
  
  <p>Like on this image:</p>
  
  <p><img src="https://i.stack.imgur.com/orVUl.png" alt="enter image description here"></p>
  
  <p>Up vector is perpendicular to normal vector. Now I want to find unique rotation from one object to another, how to do that?</p>
  
  <p>I have one method to find rotation between one vector to another, and it works. The problem is that I need to take care the two vectors: normal vector and up vector. If I use this method to rotate normal vector from object one to normal from object two, the up vector could be pointing wrong way, and they needs to be parallel.</p>
  
  <p>Here is the code for finding the shortest rotation:</p>
  
  <pre><code>GE::Quat GE::Quat::fromTo(const Vector3 &amp;v1, const Vector3 &amp;v2)
  {
      Vector3 a = Vector3::cross(v1, v2);
      Quat q;
  
      float dot = Vector3::dot(v1, v2);
  
      if ( dot &gt;= 1 ) 
      {
          q = Quat(0,0,0,1);
  
      }
      else if ( dot &lt; -0.999999 )
      {
          Vector3 axis = Vector3::cross(Vector3(1,0,0),v2);
  
          if (axis.length() == 0) // pick another if colinear
                  axis = Vector3::cross(Vector3(0,1,0),v2);
          axis.normalize();
          q = Quat::axisToQuat(axis,180);
      }
      else
      {
          float s = sqrt( (1+dot)*2 );
          float invs = 1 / s;
  
          Vector3 c = Vector3::cross(v1, v2);
  
          q.x = c.x * invs;
          q.y = c.y * invs;
          q.z = c.z * invs;
          q.w = s * 0.5f;
      }
      q.normalize();
      return q;
  }
  </code></pre>
  
  <p>What should I change/add to this code, to find the correct rotation?</p>