0

I want to separate left- and right-vision fields of a turtle in NetLogo. Left-vision field means angles are -179 to -1 degrees while right-vision field means angles are from 1 to 179 if an angle of front of a turtle is 0 degrees.

In NetLogo, patch-right-and-ahead and patch-left-and-ahead can separate left- and right-vision fields of a turtles, but those codes is only a angle incorporate a turtle. And, in-cone can not separate the vision fields.

Is there any codes to program this in NetLogo?

Y S
  • 11
  • 1

1 Answers1

2

You can save the turtle's current heading, turn it 90-degrees left and see what's on the left side of the original heading with

scan x 180

then turn it 90-degrees right from original heading and see what's on the right side of the original heading with

scan x 180

then turn it back to its original heading.

Here's code that illustrates this. Set the scan angle to something smaller than 180 to see more clearly what's happening. As you step through the go step it rotates and highlights what it is seeing.

globals [ scan-angle]
turtles-own [ actual-heading ]

to setup
  clear-all
  set scan-angle 180
  create-turtles 1 [ set size 4 set heading 0 set actual-heading heading]
  reset-ticks
end

to go
  ask turtle 0 [ set heading (heading + 30) set actual-heading heading]
  scansides scan-angle
  tick
end

to scansides [ angle ]
  ask patches [ set pcolor black] 
    ask turtle 0 
  [ 
    ;; scan left side
    set heading (actual-heading - 90) 
    ask patches in-cone 10 angle [ set pcolor red]
    ;; scan right side
    set heading (actual-heading + 90) 
    ask patches in-cone 10 angle [ set pcolor green]
    set heading actual-heading
  ]
end
Wade Schuette
  • 1,455
  • 1
  • 8
  • 9