How to modify the mesh generated from meshgrid to create a rectangular void in the middle of the mesh

65 views (last 30 days)
Hi , I'm new to matlab and trying to create a void or remove the points within a rectangular area in the mesh grid. I have to use this meshgrid to generate structured mesh for FEA.
The mesh grid is ;
[x y] = meshgrid([0: 1: 15],[0: 0.5 :13])
The x & y coordinates for the four corner points of rectangular area ; p1= [5.6 3.8] ; p2= [9.4 3.8] ; p3 =[9.4 9.2] ; p4= [3.8 9.2]
How do I do this?If this is not possible, please provide advise how to select the points/element nodes witin the rectangular area. I appreciate if someone can provide some help on this.
Thanks

Answers (2)

Epsilon
Epsilon on 27 Nov 2024 at 16:27
Edited: Epsilon on 27 Nov 2024 at 16:31
Hi Prasad,
To create a void set the values at the indices to 'NaN'.
[x, y] = meshgrid(0:1:15, 0:0.5:13);
voidIndices = (x >= 5.6 & x <= 9.4) & (y >= 3.8 & y <= 9.2);
% Remove points inside the rectangle by setting them to NaN
x(voidIndices) = NaN;
y(voidIndices) = NaN;
plot(x, y, 'b.');
To know more about 'NaN' refer to the link: https://www.mathworks.com/help/matlab/ref/nan.html?
  3 Comments
Walter Roberson
Walter Roberson on 28 Nov 2024 at 6:30
You cannot do this using delaunayTriangulation . delaunayTriangulation does not give the possibility of excluding an area. delaunayTriangulation() only accepts finite coordinates.
If you extract the non-nan values from x and y:
[x, y] = meshgrid(0:1:15, 0:0.5:13);
voidIndices = (x >= 5.6 & x <= 9.4) & (y >= 3.8 & y <= 9.2);
% Remove points inside the rectangle by setting them to NaN
x(voidIndices) = NaN;
y(voidIndices) = NaN;
XY = rmmissing([x(:), y(:)]);
DT = delaunayTriangulation(XY(:,1), XY(:,2))
DT =
delaunayTriangulation with properties: Points: [388x2 double] ConnectivityList: [692x3 double] Constraints: []
triplot(DT)
Notice that you get triangles crossing the void. The large space shown there is not void -- it is a pair of large triangles occupying the area enclosed.
Prasad
Prasad on 28 Nov 2024 at 9:43
Thank you for your advise with the outputs. I appreciate your support. Now understand the issue. Any other suggetions to obtain triangluar element mesh with a void for Finite Element Analysis.
Thanks

Sign in to comment.


Walter Roberson
Walter Roberson on 27 Nov 2024 at 20:05
You might be better off taking a different approach. You might be better off decomposing a geometry
If you follow the steps from the examples at https://www.mathworks.com/help/pde/ug/decsg.html you should be able to build a decomposed mesh. You might then fegeometry the result.
  2 Comments
Prasad
Prasad on 28 Nov 2024 at 1:56
Hi Walter,
Thank you for your advise. I'm struggling to get the mesh that I mentioned in the reply to Epsilon. I appreciate if you could provide your thoughts.
Thanks
Walter Roberson
Walter Roberson on 28 Nov 2024 at 20:03
You can follow the steps given at https://www.mathworks.com/help/pde/ug/create-geometry-at-the-command-line.html to create two rectangles, and then set the function to be R1-R2 and then [dl,bt] = decsg(gd,sf,ns); to get the decomposed geometry in a form suitable for use with the PDE toolbox.

Sign in to comment.

Tags

Products


Release

R2024a

Community Treasure Hunt

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

Start Hunting!