使链接最接近netlogo中特定点的最佳方法是什么?
最好的方法是一个链接报告器link-distancexy
,该报告器取xcor
和,ycor
然后输出从该点到链接上某个点的最接近距离。次佳的选择是一般记者closest-link-xy
,他会xcor
与ycor
并报告最接近的链接。
通过包装边界使此问题变得复杂,但是不完善的解决方案仍然值得赞赏。
吉姆·里昂(Jim Lyon)的答案为我提供了使用基本三角形几何的确切解决方案:
to-report link-distance [ x y ]
let a [ distancexy x y ] of end1
let b [ distancexy x y ] of end2
let c link-length
let d (0 - a ^ 2 + b ^ 2 + c ^ 2) / (2 * c)
if d > c [
report a
]
if d < 0 [
report b
]
report sqrt (b ^ 2 - d ^ 2)
end
这适用于包装和非包装的世界。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句