本文介绍了在NetLogo中获取最接近的链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使链接最接近netlogo中特定点的最佳方法是什么?

What's the best way to get the link closest to a particular point in netlogo?

最好是链接报告器link-distancexy,该报告器使用xcorycor并输出从该点到链接点的最接近距离.下一个最好的选择是一般报告员closest-link-xy,该报告员使用xcorycor并报告最接近的链接.

The best would be a link reporter link-distancexy that takes an xcor and ycor and outputs the closest distance from that point to a point on the link. Next best would just be a general reporter closest-link-xy that takes and xcor and ycor and reports the closest link.

此问题由于包装边界而变得复杂,但是不完善的解决方案仍然值得赞赏.

This problem is complicated by wrapping boundaries, but an imperfect solutions would still be appreciated.

推荐答案

吉姆·里昂(Jim Lyon)的答案为我提供了使用基本三角形几何形状的精确解决方案:

Jim Lyon's answer pointed me to the exact solution using basic triangle geometry:

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

这适用于包装和非包装的世界.

This works for both wrapping and non-wrapping worlds.

这篇关于在NetLogo中获取最接近的链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 05:52