以这样一种尊重世界包装的方式获得一个智能体相对于另一个智能体的坐标的最好方法是什么?
也就是说,天真的解决方案是:
to-report relative-xcor [ other-agent ]
report [ xcor ] of other-agent - xcor
end
(与ycor
类似)该代码的问题在于,例如,当主代理在屏幕的最右侧,而other-agent
在最左侧时,该代码将是错误的。
想法?到目前为止,我最好的想法是使用towards
和三角函数,但我想知道是否有更好的方法。
编辑:
举一个例子来说明为什么上面的说法是错误的,假设你的世界有min-pxcor = -5
和max-pxcor = 5
,并且有包装。如果我们在xcor = 5
有turtle 0
,在xcor = -5
有turtle 1
,那么[ relative-xcor turtle 1 ] of turtle 0
会给出-10
,而正确的答案是1
(由于世界包装)。我认为在我的问题中隐含的是它应该给出最小的(按绝对值)相对坐标。
发布于 2018-01-21 03:30:42
(这里的操作)所以到目前为止我想出的唯一解决方案是:
to-report rel-xcor [ other-agent ]
report ifelse-value (self = other-agent) [
0
] [
0 - (sin towards other-agent) * distance other-agent
]
end
to-report rel-ycor [ other-agent ]
report ifelse-value (self = other-agent) [
0
] [
0 - (cos towards other-agent) * distance other-agent
]
end
(回想一下,由于sin
的角度是翻转的,所以cos
给出y坐标,netlogo给出x)
但这似乎过于复杂了。但是,如果任何人在这个问题上遇到同样的问题,想知道同样的事情,这就是我目前使用的。不过,我很乐意接受一个更好的答案。
https://stackoverflow.com/questions/48333626
复制相似问题