我需要帮助,了解如何使用Netlogo编写此公式。 (参见附图) 我通过计算领导者的标题和代理人的标题之间的2个角度的平均值来尝试为代理设置新标题。代理的新标题应更改为27.下面是我使用的代码,但它不能按我想要的方式工作:
to change-heading
let nearby-leaders turtles with [leader? ]
if any? nearby-leaders in-radius vision
[turn-towards average-heading-towards-leaders max-cohere-turn ]
end
to-report average-heading-towards-leaders
let nearby-leaders turtles with [leader? ]
report average-heading ([heading] of one-of nearby-leaders ) heading
end
to-report average-heading [a b]
report (a - (subtract-headings a b) / 2) mod 360
end
真的需要这方面的建议,谢谢你的帮助。
答案 0 :(得分:2)
它回避了三角,但这有效
to-report average-heading[a b]
Let h (a - (subtract-headings a b) / 2) mod 360
Let s (a + b) / 2
Ifelse h < s [report h][report s]
]
end
在您的代码中
to-report average-heading-towards-leaders
report average-heading ([heading] of one-of nearby-leaders turtles with [leader? ] ) heading
end
Mark II