It might be worth backing up and describing what you need to do (perhaps in a new question).
I've played with alpha shape for a while and think I understand what you are fighting with:
Both the <<get hull path and <<get hull points return a bunch of segments in scrambled order. Path covers up the problem by drawing all the segments using a move/draw for each; this makes 1 or more visual polygons, but not with a sequential border that works for filling a polygon. The points version returns the same data (as indexes into the <<getpoints data), and it can be used just like the path version...but again, not for filling.
If there is only a single outline for one polygon, it isn't too hard to sort the segments into a nice loop. If there are multiple polygons that don't share vertices, it is only a little harder. But if there are shared points between polygons the problem seems quite hard. If you turn the alpha up much, there will often be multiple polygons sharing points.
If you want to experiment with sorting the polygon edges into a loop, consider using a JSL list to hold the indexes. You can put the first edge in the list something like this
plist = {};
ie = 1; // index to an edge
from = hullEdges[ie, 1];
dest = hullEdges[ie, 2];
Insert Into( plist, from ); // append to empty list
Insert Into( plist, dest );
you can then walk through the hulledge matrix looking for edges that connect at the beginning or end of plist:
found = 1;
While( found,
found = 0;
For( je = 1, je <= ne, je += 1,
testfrom = hullEdges[je, 1];
testdest = hullEdges[je, 2];
If(
from == testdest,
// add to left end
Insert Into( plist, testfrom, 1 );
from = testfrom;
pointCounts[testfrom] -= 1;
pointCounts[testdest] -= 1;
found = 1;//
, /*else */ dest == testfrom, //
// add to right end
Insert Into( plist, testdest );
dest = testdest;
pointCounts[testfrom] -= 1;
pointCounts[testdest] -= 1;
found = 1;
);
);
);
);
If you successfully collect the indexes to the points, you can make a polygon, something like this:
// {x2, y2} = ashape2 << getPoints;
// gather the polygon x and y matrices
idx = plist;
xdata = x2[idx];
ydata = y2[idx];
Transparency( .2 );
Fill Color( HLS Color( (ie + 1) / ne, .5, 1 ) );
Polygon( xdata, ydata, <<fill( 1 ) );
you might want something like this to check if there are points used by more than two edges:
np = ashape2 << getnpoints;
// most points are in 2 segs. some are in 4 segs.
pointCounts = J( np, 1, 0 );
If( N Rows( hullEdges ) > 0,pointCounts[hullEdges]++);
If( !All( pointCounts == 2 ),
Print( "too complicated" )
);
That middle statement uses a 2-d matrix to index a matrix of counts and increment the counts 0, 2, or 4 times.
if you have multiple polygons, you might need to keep up with which points have been used already and wrap another JSL loop around your code to find a new starting point.
Craige