取得邻近海龟的平均航向 [英] Get mean heading of neighboring turtles

查看:79
本文介绍了取得邻近海龟的平均航向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图对海龟进行编程,使其移动的方向是其邻居的平均方向(特定半径内的海龟).我应该使用半径范围内的距离吗?

I was trying to program my turtles to move with a heading that's the mean heading of its neighbors (turtles within a specific radius). Should I use in-radius to achieve this?

推荐答案

鉴于Nicolas对Arthur的回答,这里是获取

Given Nicolas' response to Arthur's answer, here's the code to get what wikipedia considers to be the mean of angles:

to-report mean-heading [ headings ]
  let mean-x mean map sin headings
  let mean-y mean map cos headings
  report atan mean-x mean-y
end

请注意,因为NetLogo角度up为0,所以sin headingx而不是y.接下来,我们可以使用它来设置乌龟的heading:

Note that because up is 0 is NetLogo angles, sin heading is the x instead of y. Next, we can use that to set the heading of our turtles:

ask turtles [
  set heading mean-heading [ heading ] of turtles in-radius 3
]

,您将用您选择的半径替换3.您没有说是否要让海龟在计算均值时考虑其自身的航向.在这里,它们确实考虑了自己的标题,这意味着我们不必进行any?检查(因为turtles in-radius r将始终包括乌龟本身!).

where you'd replace 3 with the radius of your choice of course. You didn't say if you wanted a turtle to take into account its own heading when computing the mean or not. Here, they do take their own heading into account, which means that we don't have to do an any? check (since turtles in-radius r will always include the turtle itself!).

这篇关于取得邻近海龟的平均航向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆