Collision Detection crowd netlogo - netlogo

This is what I have. I need turtles to move from circle formation and
move to another spot while preventing collisions and getting into a
circle again.
;;creates circle of people
turtles-own [collides?]
to setup
clear-all
setup-circle
reset-ticks
end
to setup-circle
create-ordered-turtles crowd-size [
set shape "person" fd 10 rt 90]
end
to go
ask turtles [
fd .1
]
tick
end

Related

Netlogo: apparent erratic behavior of turtle

I have a model where humans and a door are created. Humans face the door and run to it and exit. The problem is that some humans stop for some reason. Even if only one human is used, it some times reaches the door, and some times it doesn't. What do I have to do so humans always reach the door? This is the model, and this is the code:
globals [ID-door]
breed [door doors]
breed [human humans]
to setup
clear-all
set-default-shape door "star"
crt number [
setxy random-xcor random-ycor
set color cyan
set breed human]
new-door
reset-ticks
end
to new-door
ask one-of patches [sprout-door 1]
ask door [
set color yellow
set size 2
set ID-door who]
end
to go
if count human = 0 [stop]
ask human [
move-human
check-door]
tick
end
to move-human
face doors ID-door
ifelse any? human-on patch-ahead 1
[rt random 40 lt random 40]
[fd 1]
end
to check-door
if any? door-on patch-here [die]
end
Your problem is patch-ahead 1. This looks a distance of 1 in whatever direction the turtle is facing. Imagine the turtle is at the top left corner and looking toward the bottom right corner. The distance to the corner is >1 and the turtle is triggering the 'stay here' check and will be stuck until it is sufficiently turned around so that there is a different patch in front of it.
So you need to get the turtle to exclude itself from the check, which is a job for other. Change ifelse any? human-on patch-ahead 1 to ifelse any? other human-on patch-ahead 1.
I changed the move-human procedure to the following, and now the model works:
to move-human
ifelse patch-ahead 1 = nobody or any? other humans-on patch-ahead 1
[rt random 40 lt random 40]
[fd 1
face door ID-door]
end
As stated by JenB, patch-ahead 1 was the problem, so:
a) Because the world has horizontal and vertical limits (it´s not a wrapped space) the line patch-ahead 1 = nobody checks the absence of patches when such limits are reached.
b) The line other humans-on patch-ahead 1 excludes the current turtle as it may be counted because of the possibility that the distance of 1 may still be inside the current patch, like this image:

How to move turtles back to the patches that it come from

I have built the road shapefile which already intersected with patches. I want the turtle to move on the road that I had assigned.
to go
ask turtles
[
step
avoid-wall
]
tick
end
to-report coinflip?
report random 2 = 0
end
to avoid-wall
if [pcolor] of patch-ahead 3 = black [set heading heading - 180]
end
to step
ifelse coinflip? [rt random 60] [lt random 60]
fd random 3
end
Actually, I intend to let the turtle move out of the assigned patches. But I still want them to come back in the next tick or just the few tick later. Some turtles come back and some do not (according to my code). How should I fix the code?
I have tried to use this code in Turtles moving in a pattern (Netlogo) but it does not work (I think that it does not work because my patches are a narrow road, not an area.)

In netlogo, how do you rotate the shape of turtle without changing heading?

In other words, how do I accomplish rotation (via a command, and not through shape editor) and translation of a turtle independently.
Here's sample code that makes turtles move forward while appearing to be facing in another direction entirely:
turtles-own [real-heading apparent-heading]
to setup
clear-all
create-turtles 10 [
set real-heading random 360
set apparent-heading random 360
set heading apparent-heading
]
reset-ticks
end
to go
ask turtles [ set heading real-heading ]
ask turtles [ fd 1 rt random 25 lt random 25 ]
ask turtles [
set real-heading heading
set heading apparent-heading
]
tick
end
assuming your model is set to tick-based updates (as opposed to continuous updates), your user will only ever see the turtle's apparent heading in the view, never the turtle's "real" heading.

How to get connected two or more turtles within radius NetLogo

I have more turtles moving in the world, i would like to get them connected when they are inside an area (circles).
This is an example:
I was trying with a function like this, called in the "go" procedure (tick advanced) but this doesn't work.
Any suggestion?
to connect
ask turtles in-radius radius [
create-link-from myself
create-link-to myself
]
end
If I have understood what you want, this will work
globals [radius]
to setup
clear-all
create-turtles 50 [setxy random-xcor random-ycor]
set radius 5
connect
end
to connect
ask turtles
[ ask other turtles in-radius radius
[ create-link-from myself
]
]
end
The problem is that you have ask turtles in-radius ... but you don't specify the reference point. That is, within a certain distance of what? In my code, I ask each turtle to become the reference point and then ask the turtles within distance of itself to do the linking.

Move turtles around a patch

I am trying to move turtle around patch 0 0 starting from random position in world. But circle keeps on growing. What am I doing wrong here?.
Code:
to setup
clear-all
create-turtles 5
ask turtles [
setxy random-xcor random-ycor
]
ask patch 0 0 [ set pcolor green ]
reset-ticks
end
to go
move-turtles
tick
end
to move-turtles
ask turtles
[
face patch 0 0
right 90
fd 0.01
set pen-size 3
pen-down
]
end
Secondly I want a turtle to move around any patch I define when it reaches with in a certain range
Your approach is to take a small step along a tangent to the circle you want, but this takes you a little bit outside the circle. You do this repeatedly, so it accumulates over time.
For a better way, see the Turtles Circling example in the NetLogo Models Library.