2016-02-13 47 views
2

我正在調查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 

回答

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是龜標題所以我們所看到的是

程序報告 烏龜標題的正弦值的總和反正切,總和正弦和餘弦海龜的餘弦。

如果我們把標題和海龜的數量分開,我們最終會遇到很多問題,所以它顯然是這組角度的平均標題。

+0

所以這給出了一個平均標題? – Newguy

+1

對不起。是的,這給出了平均標題, –

+0

好的,謝謝。這段代碼似乎實現了循環數量的意思?我錯過了atan的論點 – Newguy