matble中生成Voronoi图
发布日期:2021-06-30 11:34:44 浏览次数:2 分类:技术文章

本文共 1790 字,大约阅读时间需要 5 分钟。

 

 

Definitions

Consider a set of coplanar points P. For each point Px in the set P, you can draw a boundary enclosing all the intermediate points lying closer to Px than to other points in the set P. Such a boundary is called a Voronoi polygon, and the set of all Voronoi polygons for a given point set is called a Voronoi diagram.

Visualization

Use one of these methods to plot a Voronoi diagram:

                      If you provide no output argument, voronoi plots the diagram.

                      To gain more control over color, line style, and other figure properties, use the syntax [vx,vy] = voronoi(...). This syntax returns the vertices of the finite Voronoi edges, which you can then plot with the plot function.

                      To fill the cells with color, use with n = 2 to get the indices of each cell, and then use and other plot functions to generate the figure. Note that patch does not fill unbounded cells with color.

Examples

Example 1

This code uses the voronoi function to plot the Voronoi diagram for 10 randomly generated points.

x = gallery('uniformdata',[1 10],0);

y = gallery('uniformdata',[1 10],1);

voronoi(x,y)

Example 2

This code uses the vertices of the finite Voronoi edges to plot the Voronoi diagram for the same 10 points.

x = gallery('uniformdata',[1 10],0);

y = gallery('uniformdata',[1 10],1);

[vx, vy] = voronoi(x,y);

plot(x,y,'r+',vx,vy,'b-'); axis equal

Note that you can add this code to get the figure shown in Example 1.

     xlim([min(x) max(x)])

     ylim([min(y) max(y)])

Example 3

This code uses and patch to fill the bounded cells of the same Voronoi diagram with color.

x = gallery('uniformdata',[10 2],5);

[v,c]=voronoin(x);

for i = 1:length(c)

if all(c{i}~=1)   % If at least one of the indices is 1,

                  % then it is an open region and we can't

                  % patch that.

patch(v(c{i},1),v(c{i},2),i); % use color i.

end

end

 

转载地址:https://iteblog.blog.csdn.net/article/details/7264500 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:House of Quality
下一篇:linux中的C里面使用pthread_mutex_t锁

发表评论

最新留言

哈哈,博客排版真的漂亮呢~
[***.90.31.176]2024年04月10日 23时48分36秒