Netlogo 将世界分为上层和下层

问题描述 投票:0回答:1

我正在Netlogo的一个程序中工作,我想将世界分为上象限和下象限,并要求海龟移动到上象限。我已经从这里回答的上一个问题中弄清楚如何将世界划分为四个象限,但我不知道如何将其划分为两个。

ask patches with [ pxcor <= max-pxcor and pxcor > 0  and pycor > 0]
  [
    set pcolor red
    set quadrant 1

  ]

  ask patches with [ pxcor >= min-pxcor and pxcor < 0  and pycor > 0]
  [
    set pcolor blue
    set quadrant 2
  ]

  ask patches with [ pxcor <= max-pxcor and pxcor > 0  and pycor < 0]
  [
    set pcolor green
    set quadrant 3
  ]

  ask patches with [ pxcor >= min-pxcor and pxcor < 0  and pycor < 0]
  [
    set pcolor yellow
    set quadrant 4
  ]
netlogo
1个回答
4
投票

鉴于您对下象限和上象限感兴趣,您只需要查看 y 坐标。具体条件取决于你的世界原点(即坐标[0;0])在哪里。

如果您的世界原点位于默认位置,即中心,则执行以下操作:

patches-own [
 quadrant 
]

to setup
  clear-all
  ask patches [
   ifelse (pycor > 0)
    [set quadrant 1]
    [set quadrant 2]
  ]
end

如果你的世界的原点在一个角落(例如,我假设在这种情况下是左下角),只需执行以下操作:

patches-own [
 quadrant 
]

to setup
  clear-all
  ask patches [
   ifelse (pycor > max-pycor / 2)
    [set quadrant 1]
    [set quadrant 2]
  ]
end

如果您事先不知道您的世界的原点在哪里,或者您的世界的原点比上面两个示例不太常见,您可以采取适合任何情况的更通用的方法:

patches-own [
 quadrant 
]

to setup
  clear-all
  
  let y-extent (max-pycor - min-pycor + 1)
  ask patches [
   ifelse (pycor > y-extent / 2)
    [set quadrant 1]
    [set quadrant 2]
  ]
end
© www.soinside.com 2019 - 2024. All rights reserved.