在两个多边形之间计算从边到边距离的最近多边形块

时间:2014-06-02 17:19:29

标签: netlogo

我的目标是在两个多边形之间找到从边缘到边缘距离的最近的多边形补丁。从edge to edge distance between patches with netlogo开始,这是我的代码,用于查找最近的多边形边:

to-report calculate-distance [ID-polygon-A ID-polygon-B] 

let polygon-distance nobody
let edges-of-polygon-A create-edge-turtles ID-polygon-A 
let edges-of-polygon-B create-edge-turtles ID-polygon-B 
set polygon-distance min [ min [ distance myself ] of edges-of-polygon-B ] of edges-of-polygon-A 

## find the nearest edge in the polygon A
let nearest-edge-in-polygon-A edges-of-polygon-A with-min [ min [ distance myself ] of edges-of-polygon-B] 
ask nearest-edge-in-polygon-A [ 
  set color red
  set shape "x"
  set size 2 ]

## find the nearest edge in the polygon B
let nearest-edge-in-polygon-B edges-of-polygon-B with-min [ min [ distance myself ] of edges-of-polygon-A] 
ask nearest-edge-in-polygon-B [ 
  set color red
  set shape "x"
  set size 2 ]

ask edges-of-polygon-A with [ shape = "dot"] [ die ] 
ask edges-of-polygon-B with [ shape = "dot"] [ die ] 

report polygon-distance 
end 

How to find a patch with a specific ID where there is a red turtle?开始,我的代码是从最近边找到最近的补丁:

show patches with [ ID-polygon = [ my-ID-polygon ] of myself and any? (turtles-here with [ color = red and shape = "x" ])

我不明白为什么会得到:

(agentset, 1 patch)
(agentset, 0 patches)

然而,形状=“x”的两只乌龟在多边形上很清晰可见。如果我的代码不正确,还有另一种方法可以根据距离找到两个最接近的多边形补丁吗?

提前感谢您的帮助。

0 个答案:

没有答案