【发布时间】: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 正方形。我希望这段代码能够适应任何维度。