如何找到与正方形周长相交的voronoi图悬伸线的内切点?

时间:2019-08-13 05:11:58

标签: matlab voronoi

我正在尝试通过查找与定义的正方形周长相交的悬置多边形线的交点来更新voronoi的交点数组。我希望能够重新创建一个新的voronoi相交点数组,该数组应将这些悬垂点替换为相交的点。

下面有一些我为实验创建的代码。

 C:\hanu\cordova-res-master\cordova-res-master>cordova-res
    internal/modules/cjs/loader.js:584
        throw err;
        ^

    Error: Cannot find module 

'C:\Users\HanojBudime\AppData\Roaming\npm\node_modules\cordova- 
    res\bin\cordova-res'
        at Function.Module._resolveFilename 
    (internal/modules/cjs/loader.js:582:15)
        at Function.Module._load (internal/modules/cjs/loader.js:508:25)
        at Function.Module.runMain (internal/modules/cjs/loader.js:754:12)
        at startup (internal/bootstrap/node.js:283:19)
        at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)

例如

voronoi图中的某些形状的点超过某个点,并且保持打开状态。假设我们的正方形是1x1。本质上,我们希望这些开放坐标和交点封闭该多边形。 代替此数组: (形状37)

function grainnum = sentuarusgrain(L,H,grainsize,numsamples,plot_grain)

for r=1:numsamples

    n = randi([10,50],1,1);%chooses random number between 0 to 100. n is our randomizer factor
    random = grainsize*n;
    x = gallery('uniformdata',[1,random],1); %set of points for  x that depends on grainsize*n
    y = gallery('uniformdata',[1,random],0);
    x = x*L;
    y = y*H;

    [v,c] = voronoin([x(:) y(:)]); %returns an array V with vertices and a cell array C with a matrix for each cell of the diagram. 
    for k = 1 : numel(c) %in the cell c , every 1 corresponds to a inf vector
        c{k} = c{k}(c{k} ~= 1);%gets rid of 1 in cell array C
    end


    for i=1:random
        % First we make a new matrix that has each of the required elements for the desired format
        % The index of x, the value of x, the index of y and the value of y
        TEMParea = polyarea(coord(:, 1),coord(:, 2));
        TOTALarea = TOTALarea + TEMParea;
        tempCoord = [coord(:, 1).'; coord(:, 2).'];
        coord

    end

    %VSgraph(:, 1) = random;
    random
    AVERAGEarea = TOTALarea/random
    %VSgraph(:,2) = AVERAGEarea;
    VSgraph(:,r) = random;
    VSgraph(:,r+1) = AVERAGEarea;
    VSgraph

    if plot_grain == 1

        rectangle('Position',[0,0,L,H]);% makes a section with LxH dimensions. Variables in the function parameters
        hold on
        xlim([0 L])
        ylim([0 H])
        a = voronoi(x,y);
        %plots the whole voronoi diagram
        figure;a;

        %labels the points in voronoi
%         Hpl = text(x,y, plabels, 'FontWeight', ...
%         'light', 'HorizontalAlignment','center', ...
%         'BackgroundColor', 'none');

        axis equal
        hold off
   end

end

end

This is what the diagram looks like:

请注意在正方形外面留下的悬垂线。 我希望用这些点更新坐标数组。

enter image description here

突出显示的区域是形状37 新的coord数组应如下所示:

coord =

    0.1448    0.7194
    0.1729    0.7858

代码应针对所有突出的形状执行这些操作。 我想要这种形状的目的是我想要一个正方形,只有在那个正方形中才有voronoi图。

要运行功能类型:

sentuarusgrain(1,1,1,1),其中L,H是正方形的长度和高度。粒度,多少个样本以及是否要绘制图形(1为是,0为否)。

此代码与另一个请求不同。其他代码限制为1x1正方形。但是此函数的参数(L,H)不应仅限于1和1。

1 个答案:

答案 0 :(得分:0)

您可以采取一种捷径来避免编写其他几何相交代码。如果您在域边界(正方形的四个边)上反映了Voronoi站点,则生成的Voronoi图将包含所需的正方形边界(因为它正好位于原始站点和人工站点之间的中间位置。因此,您可以忽略Voronoi单元格对于在域外创建的所有人工站点。

这里是一个Voronoi diagram with six sites和一个扩展Voronoi diagram created after reflecting的示例,它们分别跨域边界的四个侧面中的每个Voronoi站点。

这有点贵:扩展的Voronoi图的站点是原始Voronoi图的五倍。为了提高效率,您可以首先使用原始站点创建Voronoi图,确定哪些Voronoi单元与域边界接触,然后仅反映这些站点。但是最简单的代码是仅反映所有点并计算单个Voronoi图。

相关问题