title: Find the Angle between two Bearings
body: <p>Given two bearing, how do I find the smallest angle between them?</p>
  
  <p>So for example if 1 heading is 340 degrees and the second is 10 degrees the smallest angle will be 30 degrees.</p>
  
  <p>I've attached a picture to show what I mean. I've tried subtracting one from the other but that didn't work because of the wrap around effect of a circle. I've also tried using negative degrees (180 - 359 being -180 to 0) but that got messed up when trying to calculate the angle between positive and negative number. </p>
  
  <p>I'm sure there must be an easier way that having lots of <code>if</code> statements.</p>
  
  <p>Thank for your help.
  Adam</p>
  
  <p>BTW. This is a navigation question so the radius of the circle is unknown.</p>
  
  <p><img src="https://i.stack.imgur.com/tehtP.png" alt="Finding the angle between two headings"></p>