【问题标题】:How to find intersection points of overhanging lines of Voronoi diagram intersecting a square's perimeter?如何找到与正方形周长相交的Voronoi图的悬垂线的交点?
【发布时间】:2019-08-13 05:11:58
【问题描述】:

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

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

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

例如,

Voronoi 图中的某些形状的点超过了某个点并保持打开状态。假设我们的正方形是 1x1。本质上,我们希望这些开放坐标和交点关闭该多边形。 而不是这个数组: (特别是形状 37)

coord =

    0.1448    0.7194
    0.1729    0.7858

注意离开正方形的悬垂线。 我希望用这些点更新坐标数组。

突出显示的区域特别是形状 37 新的坐标数组应如下所示:

newcoord =

    0.1448    0.7194
    0.1729    0.7858
   %intersecting points 

代码应该为所有悬垂的形状执行这些操作。 我对这个形状的意图是我想要一个正方形,而只有那个正方形是 Voronoi 图。

运行函数类型:

sentuarusgrain(1,1,1,1) for L,H 是正方形的长度和高度。粒度、样本数量以及是否要绘制图表(1 表示是,0 表示否)。

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

【问题讨论】:

  • @Arthur 不,我不希望它们在图表中突出显示。我希望他们用交点改变坐标数组。该示例适用于不同的步骤。
  • 这个问题的答案可以让你得到正方形与Voronoi图的交点坐标不是你想要的吗?
  • 是的,但我希望每次使用每个悬垂形状都更新坐标数组。前面的代码只是标记了交叉点。如果可能的话,我们是否能够调整以前的代码,使其与最近的代码相匹配?
  • 该代码也仅限于 1x1 正方形。我希望这段代码能够适应任何维度。

标签: matlab voronoi


【解决方案1】:

您可以采用一种快捷方式来避免编写额外的几何交集代码。如果您在域边界(正方形的四个边)上反映 Voronoi 站点,则生成的 Voronoi 图将包含所需的正方形边界(因为它恰好位于原始站点和人工站点之间的一半。那么您可以忽略 Voronoi 单元格对于在域外创建的所有人工站点。

这是一个Voronoi diagram with six sites 和扩展Voronoi diagram created after reflecting 的示例,每个 Voronoi 站点跨越域边界的四个边。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-07-23
    • 2018-03-03
    • 2012-11-20
    • 1970-01-01
    • 2020-12-17
    • 2012-05-18
    • 2015-08-05
    • 1970-01-01
    相关资源
    最近更新 更多