Voronoi diagram- ignore outer cells?

6 次查看(过去 30 天)
Norris
Norris 2013-3-21
Hi there,
I would like to determine point density statistics for my data by using voronoi cells but I get polygons along the outer edges that are not representative of the data.
Is it possible to ignore or remove these big polygons? or would it be wise to try and use the freeBoundary edges from DelaunayTri as a bounding box?
If the latter sounds reasonable, can someone suggest a function on how to get the vertices of the overlapping lines (freeboundary and voronoi)? I tried using the polyxpoly function but that returned some funny results (not all intersections were returned and some of them are not even true intersections).
An example of my code (adjusted from voronoi matlab example), with delaunay, freeboundary,voronoi and voronoin vertices as well as area calculations to show the biased values:
Thanx in advance :)
%%random data
x = gallery('uniformdata',[1 10],0);
y = gallery('uniformdata',[1 10],1);
xy = [x;y]';
%delaunay triangle
dt = DelaunayTri(xy);
% get freebound and retrieve coords for each line segment
fb = freeBoundary(dt);
%returns xy coords for line segment in fb
fbPts = [xy(fb(:,1),:), xy(fb(:,2),:)];
%voronoi vertices
[v1,c]=voronoin(xy);
v = v1(2:end,:); %chop off first row
% define points for polyxpoly function
xx1 = fbPts(:,1);
yy1 = fbPts(:,2);
% duplicate the first x,y points to close polygon
xx1(length(fbPts)+1) = xx1(1);
yy1(length(fbPts)+1) = yy1(1);
% xy from voronoin vertices
xx2 = v(:,1);
yy2 = v(:,2);
% find vertices for overlapping lines
[xi,yi] = polyxpoly(xx1,yy1,xx2,yy2);
% plot everything
% triplot(dt,'r');
hold all
voronoi(x,y,'b') %voronoi
% line(xx1,yy1) %plot fb
% plot(xi,yi,'*') %intersection from polyxpoly
plot(v(:,1),v(:,2),'g*') %vertices from voronoin
% calc area for each voronoin polygon
for i = 1:size(c,1)
ind = c{i}';
tess_area(i,1) = polyarea(v1(ind,1),v1(ind,2));
end

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Voronoi Diagram 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by