Matlab: How to derive the vertices (coordinates) of polygons in voronoi diagram?

后端 未结 1 812
长情又很酷
长情又很酷 2021-01-26 22:25

I have a created function file in hand which is to draw lines in image,[img]=drawline(point1,point2,color,img). It\'s used to connect any two points that are inside

相关标签:
1条回答
  • 2021-01-26 22:52

    Assuming you have this drawline function that draws lines in images, this is how you loop over the edges of Voronoi diagram of a set of points:

    %# set of points and voronoi diagram
    X = rand(10,1)*200; Y = rand(10,1)*200;
    [vx,vy] = voronoi(X,Y);
    
    %# vertices connecting the edges
    p1 = [vx(1,:);vy(1,:)];     % columns are "from" points
    p2 = [vx(2,:);vy(2,:)];     % columns are "to" points
    
    %# draw edges on top of image matrix
    img = zeros(200,200,3);
    clr = [255 0 0];
    for i=1:size(vx,2)
        img = drawline(p1(:,i), p2(:,i), clr, img);
    end
    
    0 讨论(0)
提交回复
热议问题