Get triangular meshes for any shape
조회 수: 34 (최근 30일)
이전 댓글 표시
I would like to get triangular meshes for arbitrary shapes, with the most regular triangles possible and the ability to adjust the size of the triangles.
I have an example which is close but unsatisfactory because the triangles are very irregular. The example creates a toroid, then tries to get an alphashape and then tries to convert that into a triangular mesh. It's the only way I found without importing stl files.
I only need the vertices and faces. The rest of the pdemodels stuff is nice, but not necessary.
Examples of the kinds of other shapes I need this for: Cubes, prisms, regular N-gons, spheroid, part-torroids, cones, bowls, twists, etc (with holes possible in each). Nothing is spiky or furry, or rough. All surfaces are smooth.
My emphasis on triangular meshes is just because I need to exactly specify each face, and triagular meshes are efficient way of doing that. Other regular meshes are fine.
R=5; % outer radius of torus
r=2; % inner tube radius
th=linspace(0,2*pi,4*36); % e.g. 36 partitions along perimeter of the tube
phi=linspace(0,2*pi,4*18); % e.g. 18 partitions along azimuth of torus
% we convert our vectors phi and th to [n x n] matrices with meshgrid command:
[Phi,Th]=meshgrid(phi,th);
% now we generate n x n matrices for x,y,z according to eqn of torus
x=(R+r.*cos(Th)).*cos(Phi);
y=(R+r.*cos(Th)).*sin(Phi);
z=r.*sin(Th);
shp=alphaShape(x(:),y(:),z(:));
shp.Alpha=2.5;
[elements,nodes] = boundaryFacets(shp);
nodes = nodes';
elements = elements';
model = createpde();
mesh=geometryFromMesh(model,nodes,elements);
generateMesh(model)
pdeplot3D(model)
댓글 수: 2
John D'Errico
2021년 1월 13일
You want an automatic scheme that will create a perfectly regular triangular mesh on any shape. Good luck in that.
답변 (1개)
Nipun
2024년 5월 31일
Hi James,
I understand that you want to generate triangular meshes for arbitrary shapes with regular triangles and adjustable triangle sizes. Here is a method to create a triangular mesh for a toroid using the alphaShape and generateMesh functions:
R = 5; % outer radius of torus
r = 2; % inner tube radius
th = linspace(0,2*pi,144); % partitions along perimeter of the tube
phi = linspace(0,2*pi,72); % partitions along azimuth of torus
[Phi,Th] = meshgrid(phi,th);
x = (R + r.*cos(Th)).*cos(Phi);
y = (R + r.*cos(Th)).*sin(Phi);
z = r.*sin(Th);
shp = alphaShape(x(:), y(:), z(:));
shp.Alpha = 2.5;
[elements, nodes] = boundaryFacets(shp);
nodes = nodes';
elements = elements';
model = createpde();
geometryFromMesh(model, nodes, elements);
generateMesh(model, 'GeometricOrder', 'linear', 'Hmax', 0.5);
pdeplot3D(model);
For more information on "alphaShape", "boundaryFacets" and "geometryFromMesh" functions, refer to the following MathWorks documentation:
- alphaShape function in MATLAB: https://www.mathworks.com/help/matlab/ref/alphashape.html
- boundaryFacets function in MATLAB: https://www.mathworks.com/help/matlab/ref/alphashape.boundaryfacets.html
- geometryFromMesh function in MATLAB: https://www.mathworks.com/help/matlab/ref/alphashape.boundaryfacets.html
Hope this helps.
Regards,
Nipun
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Triangulation Representation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!