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

27 visualizaciones (últimos 30 días)
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

Respuestas (3)

Epsilon
Epsilon hace alrededor de 10 horas
Editada: Epsilon hace alrededor de 10 horas
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?
  1 comentario
Prasad
Prasad hace alrededor de 1 hora
Hi Epsilon,
Thank you for your input. The codes worked. However,I'm finding issues with creatinng structured mesh using delaunayTriangulation. I want to create a mesh as shown below.
Thanks.

Iniciar sesión para comentar.


Tejas
Tejas hace alrededor de 11 horas
Editada: Tejas hace alrededor de 10 horas
Hello Prasad,
To create a rectangular void in a mesh grid, follow these steps:
  • First, create a mesh and add the vertices to a list.
[x, y] = meshgrid(0:1:15, 0:0.5:13);
polygon_x = [5.6, 9.4, 9.4, 3.8];
polygon_y = [3.8, 3.8, 9.2, 9.2];
  • Then, create a logical array to store the points that fall inside the rectangle.
insidePolygon = false(size(x));
for i = 1:numel(x)
insidePolygon(i) = inpolygon(x(i), y(i), polygon_x, polygon_y);
end
  • Set the points inside the polygon to NaN.
x(insidePolygon) = NaN;
y(insidePolygon) = NaN;
To visualize the mesh, you can use the code snippet provided below:
figure;
plot(x, y, 'b.', 'MarkerSize', 10);
hold on;
plot(polygon_x([1:end 1]), polygon_y([1:end 1]), 'r-', 'LineWidth', 2);
  1 comentario
Prasad
Prasad hace alrededor de 1 hora
Hi Tejas,
I appreciate your respone. I wan't to create a mesh as noted in the reply to Epsilon. Kindly provide your suggestions.
Thanks

Iniciar sesión para comentar.


Walter Roberson
Walter Roberson hace alrededor de 7 horas
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.
  1 comentario
Prasad
Prasad hace alrededor de 1 hora
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

Iniciar sesión para comentar.

Etiquetas

Productos


Versión

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by