Moving Vertices in a Voronoi diagram and updating
3 views (last 30 days)
Show older comments
Is it possible to move vertices using a basic update method while updating the diagram as an animation. I've seen the center points be manipulated, but not the vertices.
Thanks
0 Comments
Answers (1)
Jordan Ross
on 20 Sep 2016
Hello,
In order to animate moving the vertices in a Voronoi diagram you can return the vertices from the "voronoi" function as follows:
x = gallery('uniformdata',[1 10],0);
y = gallery('uniformdata',[1 10],1);
[vx,vy] = voronoi(x,y);
Note that by returning the vertices, the "voronoi" function does not produce a plot. You can plot the vertices and center points using the "plot" function as follows:
plot(x,y,'r+',vx,vy,'b-')
xlim([min(x) max(x)])
ylim([min(y) max(y)])
This example is available in the documentation given here: https://www.mathworks.com/help/matlab/ref/voronoi.html
In order to animate the diagram you can plot again using the updated vertices. However, to give the delay to produce the animation you need to make use of the "pause" function. http://www.mathworks.com/help/matlab/ref/pause.html
Furthermore, the "drawnow" function may be required to see the next plot immediately. http://www.mathworks.com/help/matlab/ref/drawnow.html
Consider the following example in which I animate through multiple Voronoi diagrams:
for i = 1:10
x = gallery('uniformdata',[1 10*i],0);
y = gallery('uniformdata',[1 10*i],1);
[vx,vy] = voronoi(x,y);
plot(x,y,'r+',vx,vy,'b-');
ylim([min(x) max(x)]);
xlim([min(y) max(y)]);
drawnow;
pause(0.5);
end
An alternative to plotting each time is to get a handle to original plot and to update the "XData" and "YData" parameters of the line objects. Note however that you will need to manipulate the matrices "vx" and "vy" for input to "XData" and "YData" parameters.
0 Comments
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!