Netlogo植绒模型代码说明

时间:2016-02-13 16:15:34

标签: math netlogo

我正在调查netlogo的植绒模型。它有以下代码很奇怪。这段代码 在数学上 做了什么? 如果我在数学符号中看到这一点,我会理解这一点。我想这是在netlogo中实现三角函数的方法吗?

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 > max-turn
    [ ifelse turn > 0
        [ rt max-turn ]
        [ lt max-turn ] ]
    [ rt turn ]
end

1 个答案:

答案 0 :(得分:0)

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

dy and dy是海龟标题的正弦和余弦所以我们正在看的是

程序报告 海龟标题的总和的反正切,海龟标题的余弦的总和。

如果我们只是抬起标题并除以海龟的数量,我们最终会遇到很多问题,那么它就是这组角度的平均值。