title: comparing two angles
body: <p>Given four points in the plane, <code>A,B,X,Y</code>, I wish to determine which of the following two  angles is smaller <code>∢ABX</code> or <code>∢ABY</code>.</p>
  
  <p>The angle <code>∢ABX</code> is defined as the angle of <code>BX</code>, when <code>AB</code> is translated to lie on the open segment <code>(-∞,0]</code>. Intuitively when saying <code>∢ABX</code> I mean the angle you get when you turn left after visiting vertex <code>B</code>.</p>
  
  <p>I'd rather not use <code>cos</code> or <code>sqrt</code>, in order to preserve accuracy, and to minimize performance (the code would run on an embedded system).</p>
  
  <p>In the case where <code>A=(-1,0),B=(0,0)</code>, I can compare the two angles <code>∢ABX</code> and <code>∢ABY</code>, by calculating the dot product of the vectors <code>X,Y</code>, and watch its sign.</p>
  
  <p>What I can do in this case is:</p>
  
  <ol>
  <li>Determine whether or not <code>ABX</code> turns right or left</li>
  <li>If <code>ABX</code> turns left check whether or not <code>Y</code> and <code>A</code> are on the same side of the line on segment <code>BX</code>. If they are - <code>∢ABX</code> is a smaller than <code>ABY</code>.</li>
  <li>If <code>ABX</code> turns right, then <code>Y</code> and <code>A</code> on the same side of <code>BX</code> means that <code>∢ABX</code> is larger than <code>∢ABY</code>.</li>
  </ol>
  
  <p>But this seems too complicated to me.</p>
  
  <p>Any simpler approach?</p>