title: Angle between two vectors in Matlab
body: <p>I have two points, <code>a</code> and <code>b</code>. I need to calculate the angle between them, so I treat them like vectors. However vector <code>a</code> will always be defined as [0 0 0]. Reading over the MATLAB Newsreader, "<a href="http://www.mathworks.com/matlabcentral/newsreader/view_thread/151925" rel="nofollow">Angle between two vectors</a>", three solutions are provided:</p>
  
  <pre><code>x1 = 0;
  y1 = 0;
  z1 = 0;
  x2 = 0;
  y2 = 1;
  z2 = 0;
  a = [x1,y1,z1]; b= [x2,y2,z2];
  
  theta = rad2deg(atan2(norm(cross(a,b)),dot(a,b)))
  theta = rad2deg(acos(dot(a,b)))
  theta = rad2deg(atan2(x1*y2-x2*y1,x1*x2+y1*y2)) 
  </code></pre>
  
  <p>However as <code>acos</code> has accuracy problems as theta nears zero, yet out of the three equations, only <code>acos</code> provides the correct solution. </p>
  
  <p>Should I continue to use <code>acos</code> or is there a better solution?</p>