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 thi
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
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
]
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!).