title: Finding Rotation Angles between 3d points
body: <p>I am writing a program that will draw a solid along the curve of a spline. I am using visual studio 2005, and writing in C++ for OpenGL. I'm using FLTK to open my windows (fast and light toolkit).</p>
  
  <p>I currently have an algorithm that will draw a Cardinal Cubic Spline, given a set of control points, by breaking the intervals between the points up into subintervals and drawing linesegments between these sub points. The number of subintervals is variable.</p>
  
  <p>The line drawing code works wonderfully, and basically works as follows: I generate a set of points along the spline curve using the spline equation and store them in an array (as a special datastructure called Pnt3f, where the coordinates are 3 floats and there are some handy functions such as distance, length, dot and crossproduct). Then i have a single loop that iterates through the array of points and draws them as so:</p>
  
  <pre><code>glBegin(GL_LINE_STRIP);
  for(pt = 0; pt&lt;=numsubsegements ; ++pt) {
      glVertex3fv(pt.v());
  }
  glEnd();
  </code></pre>
  
  <p>As stated, this code works great. Now what i want to do is, instead of drawing a line, I want to extrude a solid. My current exploration is using a 'cylinder' quadric to create a tube along the line. This is a bit trickier, as I have to orient openGL in the direction i want to draw the cylinder. My idea is to do this:</p>
  
  <p>Psuedocode:</p>
  
  <pre><code>Push the current matrix,
  translate to the first control point
  rotate to face the next point
  draw a cylinder (length = distance between the points)
  Pop the matrix
  repeat
  </code></pre>
  
  <p>My problem is getting the angles between the points. I only need yaw and pitch, roll isnt important. I know take the arc-cosine of the dot product of the two points divided by the magnitude of both points, will return the angle between them, but this is not something i can feed to OpenGL to rotate with. I've tried doing this in 2d, using the XZ plane to get x rotation, and making the points vectors from the origin, but it does not return the correct angle.</p>
  
  <p>My current approach is much simpler. For each plane of rotation (X and Y), find the angle by:</p>
  
  <p>arc-cosine( (difference in 'x' values)/distance between the points)</p>
  
  <p>the 'x' value depends on how your set your plane up, though for my calculations I always use world x.</p>
  
  <p>Barring a few issues of it making it draw in the correct quadrant that I havent worked out yet, I want to get advice to see if this was a good implementation, or to see if someone knew a better way.</p>