首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NetLogo -从数学生成的海龟id中获取海龟位置

NetLogo -从数学生成的海龟id中获取海龟位置
EN

Stack Overflow用户
提问于 2018-05-04 06:39:01
回答 1查看 51关注 0票数 0

我试着让四只乌龟围绕群体的中心随机旋转,但我在计算中心时遇到了麻烦。组ids是连续的(例如,0-3的乌龟是组1,4-7是组2,依此类推)。目前,我计算群中心的尝试如下:

代码语言:javascript
复制
let i 0
while [i < group_num] [ ;;iterates over each group

    ;;setup some information about the group
    let j 0
    let cmx 0
    let cmy 0
    let cmz 0
    while [j < 4] [
      set cmx (cmx + (turtles ((i * 4) + j) xcor)) ;this doesn't work
      ;set cmy (cmx + (turtles with ((who = ((i * 4) + j)) ycor ))) ;nor does this
      ;set cmz (cmx + (turtles with ((who = ((i * 4) + j)) zcor )))
    ]
    set cmx (cmx / 4)
    set cmy (cmy / 4)
    set cmz (cmz / 4) 

    ;; rest of the program
]

cmx和cmy行都告诉我缺少一个闭括号,但是所有的括号都有一个配对,程序会这样突出显示它们。有没有什么建议可以说出一只乌龟的位置?

提前感谢!

EN

回答 1

Stack Overflow用户

发布于 2018-05-04 08:07:51

这是针对NetLogo3D的,对吗?也许这个基地可以让你走上正确的道路。评论中的一些细节。使用此设置:

代码语言:javascript
复制
turtles-own [ group-id static-center my-radius]

to setup
  ca
  let i 1
  crt 16 [ 
    set group-id i
    if count turtles with [ group-id = i ] > 3 [
      set i i + 1
    ]
    set color 25 + ( 20 * group-id )
    setxyz random-xcor / 2 random-ycor / 2 random-zcor / 2
    pd
  ]
  ask turtles [ 
    ; Identify the starting center of the group, as well
    ; as each turtles distance to that point
    set static-center group-center 
    set my-radius distancexyz item 0 group-center item 1 group-center item 2 group-center

    ; Face the center point, then tilt up to be tangential
    ; to the circle the turtle should transcribe
    facexyz item 0 static-center item 1 static-center item 2 static-center
    tilt-up 90
    ask patch item 0 group-center item 1 group-center item 2 group-center [ 
      set pcolor [color] of myself 
    ]
  ]
  reset-ticks
end

这利用了一个group-center报告器,它返回组的平均xyz坐标的列表:

代码语言:javascript
复制
to-report group-center
  let my-group turtles with [ group-id = [ group-id ] of myself ]
  let group-x mean [xcor] of my-group
  let group-y mean [ycor] of my-group  
  let group-z mean [zcor] of my-group
  report ( list group-x group-y group-z )
end

这只是一个简单的go,让海龟根据半径进行tilt-down

代码语言:javascript
复制
to go
  ask turtles [
    tilt-down 180 / ( pi * my-radius )
    fd 1
  ]
  tick
end
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50164730

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档