Stephen Condor
Stephen Condor

Reputation: 241

How to create turtles at intervals along links

I have a network of links which I would like to create turtles along at equidistant intervals - much like houses along a road network.

I have played with two implementations:

1 - Create a special builder turtle that traverses the network of links before the main simulation is run and hatches turtles as it does i.e.

ask builders 
[
    navigate 1 ;my network navigation function
    if count homes in-radius 2 = 0  
    [
        hatch-homes 1 
    ]
]

2 - Alternatively, I can step through the list of links and using the position of the ends, the link-length and link-heading variables do some trig to work out where to place the home turtles. EDIT: I have now implemented the trig version - it is not perfect but it does the job.

Option 1 is easy to implement but somewhat stymied by the the in-radius variable - as on some networks links may run parallel (our close to) and very close to one another. If this is the case then the second link traversed may not get any turtles (as they are within radius of the first link's turtles - if you see what i mean). Option 2 involves trig.

Can anyone think of a smarter/simpler way of doing this?

Many thanks for looking - all advice greatly appreciated.

Upvotes: 0

Views: 93

Answers (2)

Alan
Alan

Reputation: 9610

Perhaps something like this? (Assuming you exclude the end points.)

to-report convex-combinations [#pt1 #pt2 #npts]
  ;;report list of convex cominations (endpoints excluded)
  let x1 item 0 #pt1 let y1 item 1 #pt1
  let dx21 item 0 #pt2 - x1
  let dy21 item 1 #pt2 - y1
  let wts n-values #npts [(? + 1) / (#npts + 1)]
  report map [list (x1 + dx21 * ?) (y1 + dy21 * ?)] wts
end

to-report pts-along [#link #npts]
  let locations []
  ask #link [
    ask both-ends [
      set locations lput (list xcor ycor) locations
    ]
  ]
  report convex-combinations item 0 locations item 1 locations #npts
end

to place-along [#link #nturtles]
  let locations pts-along #link #nturtles
  foreach locations [
    let x item 0 ? let y item 1 ?
    crt 1 [setxy x y]
  ]
end

Upvotes: 1

King-Ink
King-Ink

Reputation: 2096

Here is my attempt

To populate
Ask links [
                Let s 0
                Let e2 end2
                Ask end1[
                                Let dist distance e2
                                Hatch dist
                                  [
                                  Set s s + 1
                                  Set heading towards e2
                                  Fd s
                                  ]
                              ]
      ]
End

Upvotes: 0

Related Questions