Step 1: Calculate distance between nodes

Step 2: Fix a threshold of maximum radius for example, distance >=250

Step 3: Filter nodes with above condition is the neighbors

set k 0
set p 0

for {set j 0} {$j < $val(nn) } {incr j} {

set a [ expr $X1($j)-$X1($i)]
set b [ expr $a*$a]
set c [ expr $Y1($j)-$Y1($i)]
set d [ expr $c*$c]
set e [ expr $b+$d]
set f 0.5
set g [expr pow($e,$f)]

if {$g <= 250 && $i != $j} {

set k [ expr $k+1]
set nei($m) $j
set m [ expr $m+1]

}

Leave a Comment