what does `forward 1` mean in netlogo? how to specify the nearest patch of a turtle in netlogo?

故事扮演 提交于 2019-12-08 06:56:57

问题


when we ask a turtle to forward 2, does it mean:

  1. on its heading direction, move to the second nearest patch

  2. on its heading direction, move to the second nearest patch's center point

  3. on its heading direction, move to the second nearest patch's center point which is (pxcor, pycor)

which one is correct? or are they the same answer?

How do we define the nearest patch this turtle is pointing to? Is the following understanding correct?

  1. top patch: if heading is between -45(315) and 45 degree
  2. right patch: if heading is between 45 and 135 degree
  3. bottom patch: if heading is between 135 and 225 degree
  4. left patch: if heading is between 225 and 315 degree

回答1:


It means to move forward a distance of 1. The easiest way to see this is with the following code:

to setup
  clear-all
  create-turtles 1
  [ setxy 0 0
    set heading 45
    forward 1
    print xcor
    print ycor
  ]
end

Try changing the heading and see what happens. Note that patches are exactly 1 unit wide and the centre of the patch is at integer values (so patch 0 0 extends from xcor -0.5 to xcor +0.5)




回答2:


forward totally ignores patch boundaries and patch centers, so 1–3 are all incorrect. Patches don't enter into it; it's just trigonometry on the turtle's x and y coordinates. Specifically, forward 1 just means setxy (xcor + sin heading) (ycor + cos heading). The destination patch is simply whatever patch the new x and y coordinates happen to lie within. The destination may or may not be a patch center.

forward 1 might leave the turtle in the same patch (e.g. if the turtle is in the southwest corner of a patch facing northeast; the length of the diagonal is 1.414..., so forward 1 isn't enough to reach a new patch). Or, forward 1 might take the turtle to the nearest patch ahead, or to the second nearest patch ahead. (The latter can occur if the turtle just grazes the corner of a patch.)

A good model to play with to explore and understand all of these possibilities is Next Patch Example, in the Code Examples section of NetLogo's Models Library

As for the second part of your question, your definition is only correct if the turtle is initially standing on a patch center. For the general case, Next Patch Example answers that too. The next-patch procedure in that model is like your definition, but handles the general case.



来源:https://stackoverflow.com/questions/34391882/what-does-forward-1-mean-in-netlogo-how-to-specify-the-nearest-patch-of-a-tur

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!