title: Calculating distance between angles that cross -180 to 180
body: <p>I am calculating the difference, in degrees, between my mouse pointer's angle in relation to my 'vehicle's angle. I take half that distance, which I store as my offset, then move my vehicle to it, which after a few calculations, eventually moves me to my desired angle. However, when my mouse is at -185, and I move it slightly up to 185, which is only 10 degrees away, the vehicle takes the "long way around", traveling from -185, to 0, then back up to 185. I have tried many ways to let it be able to pass the -180 to 180 boundary, but had no luck.</p>
  
  <p>Heres the code:</p>
  
  <pre><code>def get_angle(self, p1, p2):
      return m.atan2(p2[1]-p1[1],p2[0]-p1[0])
  
  def update(self):
      mouse_pos = pygame.mouse.get_pos()
      self.update_vehicle(self.pos, self.get_angle(self.pos, mouse_pos), r.black)
  
  def update_vehicle(self, pos, dir, color):
      self.dir += (dir - self.dir) / 50
  </code></pre>
  
  <p>where <code>self.dir</code> is the angle my vehicle realises, and <code>dir</code> is the angle passed to it, from the mouse to itself.</p>