Moving Vertices in a Voronoi diagram and updating

조회 수: 8 (최근 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 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