NetLogo-圆锥体半径内
上面的代码表示有一个半径为3、角度为60度的圆锥体。但我希望半径在5到10之间。有办法做到这一点吗?这里有几种方法可以做到这一点。这些都适用于带有NetLogo的模型库中的Vision Cone示例模型,因此我们使用稍微不同的距离(9到30之间)使效果在视觉上变得明显。我建议使用NetLogo-圆锥体半径内,netlogo,Netlogo,上面的代码表示有一个半径为3、角度为60度的圆锥体。但我希望半径在5到10之间。有办法做到这一点吗?这里有几种方法可以做到这一点。这些都适用于带有NetLogo的模型库中的Vision Cone示例模型,因此我们使用稍微不同的距离(9到30之间)使效果在视觉上变得明显。我建议使用method1,但我会将method2包括在内,因为如果有其他逻辑可以应用于过于接近的修补程序,那么它会很有用 ask turtles [ ask patches in-cone 3 60 [ set p
method1
,但我会将method2
包括在内,因为如果有其他逻辑可以应用于过于接近的修补程序,那么它会很有用
ask turtles
[ ask patches in-cone 3 60
[ set pcolor red ] ]
你能做的就是设置一个变量来保存你要求的半径。让我们调用这个变量
vision
。所以
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
代替代码中的3
let vision
set vision 5 + (random 5)
我想首先在cone中使用
,然后使用距离对结果进行过滤是可行的。(在radius中
在这里没有帮助。)
ask turtles in-cone vision 60 [
set pcolor red
]