在 NetLogo 中,如何跟踪海龟到达世界边界后的坐标?
How to keep track of the coordinates of the turtles after they hit the boundaries of the world in NetLogo?
我正在模拟有界天使内的随机游走,我想在我的模型中计算二维海龟的 mean squared displacement。海龟都从中心开始。我不确定如何在海龟到达边界后更新它们的 xy 坐标。我要求海龟在撞墙时反弹并保存新的 xcor 和 ycor。这是我的代码:
to go
ask turtles
[; head in a random direction in range (-theta, +theta)
ifelse theta = 0
[set heading heading + 0 ]
; choose a normally distributed random angel in range (-theta, +theta)
[set heading heading + random-normal 0 (theta)]
fd step-size
set xc xc + (step-size * dx)
set yc yc + (step-size * dy)
; if your next patch is blocked:
ifelse not can-move? 1
[ set heading heading + 180
fd 1 ]
;otherwise:
[rt random-float random-normal 0 (theta)]
set xcor xc
set ycor yc
set dist sqrt (xc * xc + yc * yc)]
]
我收到错误消息:
“无法将乌龟移出世界边缘。
turtle 423 运行 SET 时出错
由程序 GO 调用
由按钮 'go' 调用。知道为什么吗?
您禁用了 grid-wrap,您的 xcor/ycor 个特工正在通过 max-pxcor/min-pxcor 和 max-pycor/min-pycor
我正在模拟有界天使内的随机游走,我想在我的模型中计算二维海龟的 mean squared displacement。海龟都从中心开始。我不确定如何在海龟到达边界后更新它们的 xy 坐标。我要求海龟在撞墙时反弹并保存新的 xcor 和 ycor。这是我的代码:
to go
ask turtles
[; head in a random direction in range (-theta, +theta)
ifelse theta = 0
[set heading heading + 0 ]
; choose a normally distributed random angel in range (-theta, +theta)
[set heading heading + random-normal 0 (theta)]
fd step-size
set xc xc + (step-size * dx)
set yc yc + (step-size * dy)
; if your next patch is blocked:
ifelse not can-move? 1
[ set heading heading + 180
fd 1 ]
;otherwise:
[rt random-float random-normal 0 (theta)]
set xcor xc
set ycor yc
set dist sqrt (xc * xc + yc * yc)]
]
我收到错误消息: “无法将乌龟移出世界边缘。 turtle 423 运行 SET 时出错 由程序 GO 调用 由按钮 'go' 调用。知道为什么吗?
您禁用了 grid-wrap,您的 xcor/ycor 个特工正在通过 max-pxcor/min-pxcor 和 max-pycor/min-pycor