我想在一组属于龟territory
的补丁周围找到构成凸包的补丁集。我计划使用“礼品包装”程序来计算凸包(与下图相关)。
我首先找到最低pxcor
的区域补丁。然后,我想从起始补丁中找到具有最小heading
(即,最接近零的角度)的区域补丁,依此类推,直到我回到起始补丁。但我似乎无法弄清楚如何计算两个补丁之间的标题。任何建议都会非常有用。这是我到目前为止所拥有的。最终,我将不得不通过外壳的每个点进行循环。
patches-own [ owner-animal ]
turtles-own [ territory ]
to setup
ca
create-turtles 1
[
move-to patch-at (max-pxcor / 2) (max-pycor / 2)
set territory patches in-radius (2 + random 8)
ask territory [
set owner-animal myself
set pcolor [ color ] of myself - 2
]
]
end
to find-convex-hull
ask turtles
[
let start-patch min-one-of territory [pxcor]
ask start-patch
[
let next-patch min-one-of [territory] of myself [towards self]
]
]
end
答案 0 :(得分:1)
我认为这可以满足您的需求。关于代码的唯一奇怪的事情是[towards myself - heading] of myself]
,其中第一个我自己引用下一个乌龟,第二个自己引用原始,因为它是我自己的。
这有意义吗?如果您有任何问题,请告诉我。
to setup
ca
crt 10 [setxy random-xcor random-ycor]
end
to start-connecting
ask min-one-of turtles [xcor][set heading 0 connect]
end
to connect
let the-turtle min-one-of other turtles with [[towards myself - heading] of myself > 0] [ [towards myself - heading] of myself]
if the-turtle = nobody [stop]
face the-turtle
ask the-turtle [set heading [heading] of myself]
create-link-with the-turtle
ask the-turtle [connect]
end
顺便说一句,如果您只想为特定的代理集执行此操作,只需在connect
过程中更改您连接的哪些海龟。