title: Calculating heading angle from 2 points?
body: <p>I'm trying to get the heading angle from two points as shown below, within -180/180 range. Clockwise measures should be positive while counterclockwise should be negative.</p>
  
  <pre><code>;Assume a view from above:
  ;
  ;              C
  ;              |
  ;              |
  ;              |
  ;            , A-------&gt;  (A's heading [A is facing this direction])
  ;        , '    `
  ;    , '          `
  ;  D                `
  ;                     `
  ;                       `
  ;                         B
  
  float fAngle = A.GetHeadingAngle(B) ;fAngle will equal 45.0
  float gAngle = A.GetHeadingAngle(C) ;gAngle will equal -90.0
  float hAngle = A.GetHeadingAngle(D) ;hAngle will equal 150.0 (approx)
  </code></pre>
  
  <p>I've tried using atan2 and the difference in coordinates of the two points to get the angle:</p>
  
  <p><code>headingangle = atan2(dy, dx) * (180.0 / MATH_PI);</code></p>
  
  <p>but it doesn't give the expected results. for example:</p>
  
  <pre><code>expected HeadingAngle = -10.443440
  actual HeadingAngle = 107.463173
  </code></pre>
  
  <p>Can any math gurus help?</p>