title: Netlogo Flocking Model Code Explanation
body: <p>I'm investigating the flocking model of netlogo. It has the following code that is strange. What does this code do <strong><em>mathematically</em></strong>? 
  If I would see this in mathematical notations I would understand this. I suppose this is how trigonometry gets implemented in netlogo ?</p>
  
  <pre><code>to heading
    turn-towards average-heading max-align-turn
  end
  
  to-report average-heading
    let x-component sum [dx] of flock
    let y-component sum [dy] of flock
    ifelse x-component = 0 and y-component = 0
      [ report heading ]
      [ report atan x-component y-component ]
  end
  
  to turn-towards [new-heading max-turn]
    turn-at-most (subtract-headings new-heading heading) max-turn
  end
  
  to turn-at-most [turn max-turn]
    ifelse abs turn &gt; max-turn
      [ ifelse turn &gt; 0
          [ rt max-turn ]
          [ lt max-turn ] ]
      [ rt turn ]
  end
  </code></pre>