How to measure distance covered across patches in NetLogo - netlogo

I have a model setup in NetLogo where the simulation space is a GIS map with a 20 km radius that I constructed.
The max xcor and ycor are set to 20 and min xcor and ycor -20. This gives a torus of 41 x 41.
I have my agents at the centre of the map at patch 0 0 and want the maximum distance they can cover as the 20 km i.e. the extent of the GIS map.
ask turtles [
set heading 360
fd 1 ]
Am I right in saying if I iterate this code 20 times they'll be at the centre of the last patch (xcor 0 ycor 20) which isn't quite 20 km?
If that's right, how do I code it up so the agents move the appropriate distance. I feel like I'm trying to square a circle here.
I should say I can add the following line to get a patch scale that comes out at about 975.6
set patch-scale (item 1 gis:world-envelope - item 0 gis:world-envelope ) / world-width
If I multiply the patch scale by the world width I get 40000 which looks right given the radius of the circle is 20 km.
Thanks

globals [km]
to test
ca
let extent 40 ;desired world-width, in kilometers
set km (world-width / extent)
crt 1 [set heading 360]
ask turtle 0 [fd (20 * km)]
end

Related

How to use Face to direct turtle movement toward a cone

How do you direct turtle movement into a cone? I want turtles to move into a cone of highest chemical. I tried face cone, but it triggered the error that
nothing named cone has been defined.
I am aware that uphill-chemical is an existing way to direct turtle movement, but it is not working in my model, since the turtles wander in and out of the trail, instead of clearly following it towards one direction.
My proposed code is:
to uphill-total-chemical-scent-in-cone
let gradient-color red ;; gradients are a temporary debugging feature
let scent-ahead total-chemical-scent-in-cone 20 0 10
let scent-ahead-2 total-chemical-scent-in-cone 20 -45 10
let scent-ahead-3 total-chemical-scent-in-cone 20 45 10
ifelse (scent-ahead-2 > scent-ahead) or (scent-ahead-3 > scent-ahead)
[ ifelse scent-ahead-3 > scent-ahead-2
[ face cone 20 45 10 hatch-gradients 1 [set color gradient-color ]] ;;
not sure how to direct movement into the cone, but could try face or some variation/ask for help
[ face cone 21 -45 10 hatch-gradients 1 [set color gradient-color ]]]
[face cone 20 0 10 hatch-gradients 1 [ set color gradient-color fd 1]]
end

Netlogo: finding min variable of patches at certain radius of patch

I'm trying to estimate slopes between patches, so need to find the minimum value of a patch variable called Elevation from all patches that are at radius 4 from a specific patch. Here is the code:
ask patch 27 35 [let x min-one-of patches in-radius 4 [Elevation]
print x]
but instead of the lowest value of Elevation, it prints: (patch 27 31). What can I do to have the value instead of coordinates?
You've got the code to find the patch with the minimum value, so all you need is the value at that patch.
ask patch 27 35
[ let low-patch min-one-of patches in-radius 4 [Elevation]
let x [Elevation] of low-patch
print x
]
But it's more straightforward to just take the minimum of the values directly (not tested so syntax may need to be adjusted)
ask patch 27 35
[ let x min [Elevation] of patches in-radius 4
print x
]

Drawing an Emergent ellipse with a turtle.

This is an answer to a question posed in the comments in my possibly poorly worded question about super-ellipses.
in Netlogo it is natural to draw geometric shapes in ways that may seem strange in other languages.
ask turtle 1 [pendown
let d (pi * distance turtle 2) / 360
repeat 360 [face turtle 2 rt 90 fd d]
]
for instance inscribes makes turtle 1 draw a circle [360-gon] around turtle 2. I did not invoke any of the standard circle formulas but still get a circle.
Is it possible to draw an ellipse in this same vernacular with say one turtle drawing an ellipse (or super-ellipse)round two other turtles using them as the foci?
Essentially to make an ellipse you set the turtles heading to the weighted mean heading of the foci and update each step. It could be done in one line but that would be one ugly line.
globals [a b c]
to setup
ca
crt 1 [set heading 90 fd 10 pendown set C self]
crt 1 [setxy 5 10 set A self]
crt 1 [setxy 0 -10 set B self]
end
to go
repeat 5100 ;; ad hoc number
[
ask c
[
let Ax [xcor] of A - xcor
let Ay [ycor] of A - ycor
let Bx [xcor] of B - xcor
let By [ycor] of B - ycor
let da 1 / distance a
let db 1 / distance B
set heading 90 + atan ((ax * da + bx * dB) / (da + db))
((ay * da + by * db) / (da + db))
FD .0125 ;;
]
]
end

Create two rows of turtles with an equal x-cor distance

first of all, sorry for my english. I hope you can understand me.
I'm trying to create an ABM of couple bargaining. In order to accomplish this, I want to set two rows of men and women, like in the "Party" Netlogo model.
As I see, I want to have one row with men disposed with equal distances between every man, like man, (5 empty patches), man (5 positions), man... starting with one on the left in a determined position. And the same goes for woman's row.
How can I do this?
With this:
setxy random-xcor 15 ; for the man's row
setxy random-xcor 15 ; for the woman's row
I can get two rows of men and women within a fixed axis, and a random-xcor on the other axis, but i don't get equal distances between turtles.
Thank you so much for your help.
ask patches with [pxcor mod 5 = 0 and abs pycor = 1] [
sprout 1 [
set shape "person"
set color ifelse-value (pycor > 0) [blue][pink]
]
]
You could do something like this:
create-turtles num-men [ setxy who * distance 15]
create-turtles num-women [setxy (who - num-men) * distance -15]
For example,
if you have 5 turtles, their whos will be [0 1 2 3 4] and a distance of 5, thus their xcors will be [0 5 10 15 20] respectively. The only reason this would work is if the men's whos start at 0. You may need to offset their whos by how many other turtles were created before...see the women.

To create fixed number turtles each with separate headings on fixed ycor and equidistant xcor

I want to create 4 turtles on fixed pycor (like pycor = 10) and even spacing xcor over that pycor; and also I want to make the headings of each turtles separate from other. The display is like
............. O ............. O .............. O ........... O ............
(heading 45) (heading 90) (heading 230) (heading 180)
O is the turtle here. My code is as below.
ask n-of 4 patches with [ pcolor = 18 and pycor = 10 ] [
sprout-turtles 1 [
set shape "default"
set color blue
set size 2
set heading one-of [90 270]
]
]
With this code turtles are created but many time with same heading, sometimes on same patch, sometimes neighboring patch as shown below
..........OOO...................O or .........OO..........O.........O...
but this i don't want. Should i have to use Create turtles four times separately specifying xcor, ycor and heading? Actually i don't want to use it four times. Please any suggestion and help? Thanks a lot.
Since the only thing you are taking from the patch to the turtle, you may as well just use create-turtles instead of sprout-turtles and then put them where you want. Typically, sprout is used when the particular patch meets relevant conditions - such as having lots of resources. Also, since you want specific values, using one-of or n-of will not work because they randomly select.
Instead you want something more like this (not tested):
let gap 15 ; spacing between turtles
let directions [45 90 230 180] ; heading values
let ii 0 ; counter / index
repeat 4
[ create-turtles 1
[ setxy (0 + ii * gap) 10
set shape "default"
set color blue
set size 2
set heading item ii directions
]
set ii ii + 1
]