Put area of Voronoi polygon to exact location
1 view (last 30 days)
Show older comments
Hello
How to match area of each voronoi polygon with location of points used to create that polygon.
I calculate area of each polygon and when I plot it is not OK. For example (see attached picture) polygon around point T9 has area 5.389, but on the picture it is 5.2436.
X = [-1.5 3.2; 1.8 3.3; -3.7 1.5; -1.5 1.3; 0.8 1.2; ...
3.3 1.5; -4.0 -1.0; -2.3 -0.7; 0 -0.5; 2.0 -1.5; ...
3.7 -0.8; -3.5 -2.9; -0.9 -3.9; 2.0 -3.5; 3.5 -2.25];
[VX,VY] = voronoi(X(:,1),X(:,2));
h = plot(VX,VY,'-b',X(:,1),X(:,2),'.r');
xlim([-4,4])
ylim([-4,4])
[V,C,XY]=VoronoiLimit(X(:,1),X(:,2));
% Compute area of each voronoi polygon
A = zeros(length(C),1) ;
for i = 1:length(C)
v1 = V(C{i},1) ;
v2 = V(C{i},2) ;
patch(v1,v2,rand(1,3));
A(i) = polyarea(v1,v2) ;
end
x=X(:,1);
y=X(:,2);
nump = size(x,1);
plabels = arrayfun(@(n) {sprintf('T%d', n)}, (1:nump)');
hold on
plot(x,y,'.')
text(x, y, plabels, ...
'FontWeight', 'bold', 'HorizontalAlignment',...
'right','BackgroundColor', 'none');
hold off
hold on
text(x,y,num2str(A),'fontsize',8,'HorizontalAlignment',...
'left');
hold off
dt = delaunayTriangulation(X);
[V,R] = voronoiDiagram(dt);
% Assign labels to the Voronoi vertices V.
% By convention the first vertex is at infinity.
numv = size(V,1);
vlabels = arrayfun(@(n) {sprintf('V%d', n)}, (2:numv)');
hold on
Hpl = text(V(2:end,1), V(2:end,2)+.2, vlabels, ...
'FontWeight', 'bold', 'HorizontalAlignment',...
'center', 'BackgroundColor', 'none');
hold off
0 Comments
Answers (0)
See Also
Categories
Find more on Voronoi Diagram in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!