I am building a model, which turtles move to the nearest green patch (cube).
nearest-patch
facexyz nearest-patch
fd distance nearest-patch
However, the angles of turtles' tilt and roll have changed after they arrive at each patch. How to make each turtle' tilt and roll to be 0 which turtle will parallel with XY plane, after they arrive on a patch. Thanks.
Turtles have pitch and roll variables that you can set like any other variables. So, you can do set pitch 0 and set roll 0 to align them with the XY plane.
Related
I am building a dispersal model in a landscape with different landcover types: urban, forest, residential etc. Each one of these landcover types has a resistance-to-movement patch variable and they are found in clusters of patches:
urban - 4 + random-float 1.0
residential - 9 + random-float 1.0
forest - 1 + random-float 1.0.
I would like my turtles to move downhill the resistance values from one forest patch cluster to another. The issue I am having however, is that because the resistance values are not distributed in a gradient, the turtles will stay put if the resistance of its neighbours is the same or move backwards away from the forest patches if the resistance is lower in that direction.
Most models in the model library that use the downhill/uphill functions have gradient landscapes such as mountains, but mine are randomly distributed.
How can I get my turtles to move downhill while also maintaining a global direction towards the forest patches so that they do not move backwards?
Thanks!
That seems rather like a modelling problem than like a Netlogo problem to me.
How would you like the turtles to move, if they have visited all forest patches in that cluster?
Two ideas:
they move to the patch with the smallest resistance from all neighbor patches, that are closer to their destination, e.g. with min-one-of
face destination ; destination is a patch
; could be a global variable set in setup
let candidates (patch-set patch-right-and-ahead 30 1
patch-left-and-ahead 30 1
patch-ahead 1)
move-to min-one-of candidates [value] ; turtle moves to the candidate patch with the smallest "value"
or, if they have knowledge of the whole landscape, they could use a path search algorithm such as A* in order to minimize the sum of resistance on their path.
when we ask a turtle to forward 2, does it mean:
on its heading direction, move to the second nearest patch
on its heading direction, move to the second nearest patch's center point
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?
top patch: if heading is between -45(315) and 45 degree
right patch: if heading is between 45 and 135 degree
bottom patch: if heading is between 135 and 225 degree
left patch: if heading is between 225 and 315 degree
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)
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.
In order for two way traffic to flow along a road that is the thickness of a single patch it is necessary for the position of each turtle to be to either the left or the right of the patch on which they are travelling. How can I control where a turtle resides on a patch while travelling along it so that there is enough space for two opposing flows of traffic on the same road?
You can use set xcor ... and set ycor ..., or setxy ... ..., or any other turtle motion command such as fd or bk, to position the turtle however you like. If the turtle's coordinates are both integers, it's on a patch center. If either or both aren't integers, then the turtle is in some other location in the patch.
I'm making a driving simulation in Netlogo 3D, and I want the car to "crash" and become the shape "fire" when it hits the side of the garage made out of colored patches that are a different color than the car and the ground. Its there a way for the turtle to detect the garage and "crash"?
patch-ahead should work in 3D.
I created a turtle in NetLogo which is moving randomly and there are some obstacles. Is it possible to get its current direction? I want to get the turtle to walk back to the center when it sees an obstacle. I can calculate distance to the center, but since I don't know its direction I can't say forward or backwards, for example.
The turtle's current direction is given by the heading variable. You can both read and write to this variable in order to change the turtle's heading. You can also change it using facexy as N. Payette mentioned.
The facexy primitive will allow you to set your turtle's heading toward the origin:
http://ccl.northwestern.edu/netlogo/docs/dictionary.html#facexy
ask turtle <who>
[If (patch-ahead = obstacle)
[
facexy origin
fd distance origin
]
]
Here obstacle and origin are the respective patches.
Building on what Jose M Vidal and N. Payette have already said.