title: Issue with finding angle between 3 points in Python
body: <p>I have 3 points p1(x1, y1), p2(x2, y2) and p3(x3, y3). I am trying to calculate <strong>angle</strong> (in <em>anti-clockwise</em> direction) between these 3 points. I am using following dot product method as provided in multiple blogs and SE sites (like <a href="https://stackoverflow.com/questions/14066933/direct-way-of-computing-clockwise-angle-between-2-vectors">this</a>). </p>
  
  <pre class="lang-py prettyprint-override"><code>def angle_between(p1, p2, p3):
      x1, y1 = p1
      x2, y2 = p2
      x3, y3 = p3
  
      v21 = (x1 - x2, y1 - y2)
      v23 = (x3 - x2, y3 - y2)
  
      dot = v21[0] * v23[0] + v21[1] * v23[1]
      det = v21[0] * v23[1] - v21[1] * v23[0]
  
      theta = np.rad2deg(np.arctan2(det, dot))
  
      print(theta)
  </code></pre>
  
  <p>It is giving me correct angle for any points which are not on the straight line. For example </p>
  
  <pre class="lang-py prettyprint-override"><code>p1 = (0, 0)
  p2 = (1, 0)
  p3 = (1, 1)
  angle_between(p1, p2, p3) # Prints -90
  angle_between(p3, p2, p1) # Prints +90
  </code></pre>
  
  <p>However, if points are on the straight line, it is giving me same answer</p>
  
  <pre class="lang-py prettyprint-override"><code>p1 = (0, 0)
  p2 = (1, 0)
  p3 = (2, 0)
  angle_between(p1, p2, p3) # Prints +180
  angle_between(p3, p2, p1) # Prints +180
  </code></pre>
  
  <p>Here I was expecting (p3, p2, p1) to give -180. What am I missing here? If the method I am using is not correct, can someone help me point towards the correct method? </p>
  
  <p>I have tried to use direct cosine law (as given <a href="https://stackoverflow.com/questions/1211212/how-to-calculate-an-angle-from-three-points">here</a>) but it only provides me angle without any sense of direction of the angle.</p>