我试着让四只乌龟围绕群体的中心随机旋转,但我在计算中心时遇到了麻烦。组ids是连续的(例如,0-3的乌龟是组1,4-7是组2,依此类推)。目前,我计算群中心的尝试如下:
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行都告诉我缺少一个闭括号,但是所有的括号都有一个配对,程序会这样突出显示它们。有没有什么建议可以说出一只乌龟的位置?
提前感谢!
发布于 2018-05-04 08:07:51
这是针对NetLogo3D的,对吗?也许这个基地可以让你走上正确的道路。评论中的一些细节。使用此设置:
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坐标的列表:
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。
to go
ask turtles [
tilt-down 180 / ( pi * my-radius )
fd 1
]
tick
endhttps://stackoverflow.com/questions/50164730
复制相似问题