NetLogo - 圆锥内半径

NetLogo - In-Cone radius

ask turtles
  [ ask patches in-cone 3 60
      [ set pcolor red ] ]

上面的代码表示有一个半径为 3、角度为 60 度的圆锥体。但是我想要一个 5 到 10 范围内的半径。有没有办法实现这个?

您可以通过以下几种方式完成此操作。这些都适用于 NetLogo 模型库中的 Vision Cone Example 模型,因此我们使用略有不同的距离(9 到 30 之间)以使效果在视觉上显而易见。我推荐 method1,但我也包括了 method2,因为如果您有一些备用逻辑可以应用于太接近的补丁,它会很有用。

to method1 
  ; use `distance` to filter those that are too close
  ; `myself` refers to the turtle doing the asking
  ask patches in-cone 30 60 with [distance myself >= 9] [
    set pcolor grey
  ]
end

to method2
  ; create a local variable to store the turtles that 
  ; will be too close.  `self` refers to the patch
  ; being asked
  let too-close patches in-cone 9 60
  ask patches in-cone 30 60 with [not member? self too-close] [
    set pcolor gray
  ]
  ; I could use the `too-close` agentset here and ask them
  ; to do something, also.
end

您可以设置一个变量来保存您要求的半径。我们称这个变量为 vision。所以,

let vision
set vision 5 + (random 5)

然后您可以用 vision 代替代码中的 3

ask turtles in-cone vision 60 [
set pcolor red
]