Moving Vertices in a Voronoi diagram and updating

2 ビュー (過去 30 日間)
grovesn
grovesn 2016 年 9 月 12 日
回答済み: Jordan Ross 2016 年 9 月 20 日
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

回答 (1 件)

Jordan Ross
Jordan Ross 2016 年 9 月 20 日
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.

カテゴリ

Help Center および File ExchangeVoronoi Diagram についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by