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)
Mostrar comentarios más antiguos
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
0 comentarios
Respuestas (3)
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?
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));
- Next, iterate over each point in the mesh grid and use the 'inpolygon' function to determine whether the points lie within the polygon or outside it. More details about this function can be found in this documentation: https://www.mathworks.com/help/releases/R2024a/matlab/ref/inpolygon.html .
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);
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.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!