【问题标题】:How to keep track of the coordinates of the turtles after they hit the boundaries of the world in NetLogo?如何在 NetLogo 中跟踪海龟到达世界边界后的坐标?
【发布时间】:2019-02-25 21:05:29
【问题描述】:

我正在模拟有界天使内的随机游走,我想在我的模型中计算 2D 中海龟的 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)]
  ]

我收到错误消息: “不能将乌龟移动到世界边缘之外。 龟 423 运行 SET 时出错 由过程 GO 调用 由按钮“go”调用。任何想法为什么?

【问题讨论】:

    标签: distance netlogo agent-based-modeling


    【解决方案1】:

    您禁用了 grid-wrap 并且您的代理的 xcor/ycor 超过了 max-pxcor/min-pxcor 和 max-pycor/min-pycor

    【讨论】:

    • 感谢您的回复。我在更新x-y坐标之前添加了“if can-move?1”的条件,我的问题就解决了!
    猜你喜欢
    • 1970-01-01
    • 2015-05-04
    • 1970-01-01
    • 2021-09-18
    • 2014-05-01
    • 2015-04-16
    • 1970-01-01
    • 1970-01-01
    • 2021-12-23
    相关资源
    最近更新 更多