// Relative Neighbourhood Graph
// This wrangle runs thru all points.
// Current point = point being ran thru
// 'nearpoints' gives you a list of point numbers near the current point
foreach(int pt; nearpoints(0, @P, 1.0, 10)) // For every point 'nearpoints' finds in the given radius..
if(pt == @ptnum) continue; // Skip itself, go to the next iteration
vector p = point(0, 'P', pt); // Store position of the near point
float dist = distance(p, @P); // Store distance (mydist) from current point to near point
// Building 2 new arrays...
// We will search for any points within the radii (mydist) of both the current and near points
// to check if they are closer to each other.
int ptsA = nearpoints(0, @P, dist); // Look for any more points around the current point within mydist...
int ptsB = nearpoints(0, p, dist); // Then, look for any more points around its near point within mydist.
int chk = 0; // Initialize a flag
foreach(int cpt; ptsB) // For every point (cpt) found in our 'ptsB' array..
if(cpt == @ptnum || cpt == pt) continue; // if cpt is the current point or near point, skip it.
chk = removevalue(ptsA, cpt); // Remove cpt from our 'ptsB' array. If successful, set our flag to TRUE.
if(chk) break; // If we successfuly removed cpt, break out of this nested loop.
// If our list 'ptsA' is empty, lets draw a line between the current point and the near point.
// If there were points left in the list, no line will be drawn.
if(!chk) // If we failed to remove a value previously...
int pr = addprim(0, 'polyline'); // create a new empty polyline
addvertex(0, pr, @ptnum); // Add a new vertex to that polyline at the position of the current point
addvertex(0, pr, pt); // Add another vertex to that polyline at the position of the near point
Im not the original author of this code. Its an example I pointed to in that link.