Remove everything outside a defined area

Hi,
I have to study the response of a cellular graded material with Abaqus, and to recreate the geometry, I'm using the Voronoi function of Matlab.
I need to cut out everything outside the area that's being defined with the letter "s", but I don't know how.
The code to recreate the area and the voronoi structure is this:
clear all; close all; clc
%Defining the area "s" I want to use to cut the portion I need
s = table([0; 0; 30; 30],[0; 10; 10; 0], ones(4,1),...
'VariableNames',{'X','Y','Z'},'RowNames',{'A','B','C','D'});
patch(s.X,s.Y,s.Z);
axis equal;
hold on
%Defining a minimum distance that the nodes have to maintain
minAllowableDistance = 0.5;
%Defining the number of nodes/points I want to generate
numberOfPoints = 2000;
%Generating the x and y coordinates randomly
x = 30*rand(1,numberOfPoints);
y = 10*rand(1,numberOfPoints);
%Here there is the cicle needed to place the points at a given distance
%from each other
keeperX = x(1);
keeperY = y(1);
counter=1;
for k = 1 : numberOfPoints
thisX = x(k);
thisY = y(k);
distances = sqrt((thisX-keeperX).^2 + (thisY - keeperY).^2);
minDistance = min(distances);
if minDistance >= minAllowableDistance
keeperX(counter) = thisX;
keeperY(counter) = thisY;
counter = counter + 1;
end
end
%Creating the voronoi structure.
voronoi(keeperX,keeperY);

 採用された回答

darova
darova 2021 年 2 月 17 日

1 投票

Try initmesh to triangulate

3 件のコメント

Edmondo D'Ercole
Edmondo D'Ercole 2021 年 2 月 18 日
Thank you, but I don't need to generate the mesh on matlab, I'll do that on abaqus. I just need to delete everything that is out of the rectangle, since there are vertices that spread to infinity.
This is what a little more complex code gives back:
and this is what I want to obtain:
darova
darova 2021 年 2 月 18 日
YOu can do something like
ind = 0<y && y<10; % find indices outside rectangle
x(ind) = []; % remove data
y(ind) = [];
Edmondo D'Ercole
Edmondo D'Ercole 2021 年 2 月 25 日
Actually this is how you solve my question. THANK YOU! The problem was with how I used the Voronoi function. I solved it this way:
[vx,vy]=voronoi(keeperX,keeperY);
ind = vx<0 | vx>30;
vx(ind) = [];
vy(ind) = [];
ind = vy<0 | vy>10;
vx(ind)=[];
vy(ind)=[];
With this, I generate the vertices of the Voronoi structure, and then cut off the vertices outside my area of interest.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeVoronoi Diagrams についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by