Let T is the list of triangle vertices, the edges are
E = unique(sort([T(:,2) T(:,1); T(:,3) T(:,2); T(:,1) T(:,3)],2),'rows')
Bruno
Great thanks. It would be much better if the delaunay function returned the edges as an optional output though.
My general problem is to compute some kind of metric for the density/compactness for a set of 2D points. My first method was to find the average distance from the mean. I'd like something that more considers distance from neighbouring points (maybe average distance between a point and its nearest neighbour). This is what I was attempting with the triangulation, although I now realise this won't work because of the long edges towards the boundary of the set of points. I need something fairly fast. Any ideas?
What Bruno suggested is the standard trick, and it will be
fast of course, but as you say, a delaunay triangulation
tends to generate long edges around the perimeter.
One option would be to use an alpha shape to delete
those long perimeter edges. Alpha shapes are fairly fast
to compute.
Another idea is to use a k-d tree to find the nearest
neighbor for all points. There are fast tools for this on
the FEX.
John
"Peter Bone" <pete...@hotmail.com> wrote in message
news:ie52q5$gtn$1...@fred.mathworks.com...
Use the edges and/or freeBoundary methods of the DelaunayTri object,
depending on what exactly you mean by "average distance of edges".
http://www.mathworks.com/help/techdoc/ref/delaunaytriclass.html
--
Steve Lord
sl...@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlab.wikia.com/wiki/FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com
Thanks. I went for the kd-tree idea. I used the kd-tree code by pramod vemulapalli.
function c = compactness2(pts)
% Compute the KD tree for fast nearest neighbour searching
tree = kd_buildtree(pts,0);
num = size(pts,1);
% Find the average distance from nearest neighbour
d_sum = 0;
for p = 1 : num
index_vals = kd_knn(tree, pts(p,:), 2,0);
d = sum((pts(p) - pts(index_vals(2))).^2);
d_sum = d_sum + d;
end
c = sqrt(d_sum / num);