Identifying all elements and their nodal coordinates given all possible nodes
12 次查看(过去 30 天)
显示 更早的评论
I generated a list of all possible nodes on the faces of my hollow cube but wanted to idenitfy every single square element that makes up the cube's faces by connecting (adjacent) nodes. What functions would I use?
0 个评论
回答(2 个)
William Rose
2024-5-29
You want to "identify every single square element". Do you have a preferred format for the "identified" faces? What do you plan to do with the info?
V=[0,0,0;0,0,1;0,1,0;0,1,1;1,0,0;1,0,1;1,1,0;1,1,1]; % vertex locations
Each row of V has x,y,z for one vertex. Columns 1,2,3 of V contain coords x,y,z of the different vertices.
F=[1,3,4,2;5,6,8,7;1,5,7,3;2,4,8,6;1,2,6,5;4,3,7,8]; % faces
Each row of array F contains the numbers of the vertices comprising 1 face of the cube.
patch('Faces',F,'Vertices',V,'FaceColor','c'); % plot the polyhedron (cube)
axis equal; xlabel('X'); ylabel('Y'); zlabel('Z'); view(-45,30)
The code above works when the vertex order is a binary counting order. If array V is not in that kind of order, you can sort it along x, y, and z to put it into that order, then use the face array F above.
If you want to plot the cube associated with a set of vertices in any order, run the code below.
F2=convhull(V); % fit a polyhedron around the vertices
figure
trisurf(F2,V(:,1),V(:,2),V(:,3),'FaceColor','r');
axis equal; xlabel('X'); ylabel('Y'); zlabel('Z')
I used convhull() to find triangular faces that cover the cube, and I use trisurf() instead of patch(). convhull() does not care about the ordering of the vertices. convhulll() returns an array whose rows are lists of vertex numbers making up each triangular face. Pass to trisurf() the array with vertex numbers for each face, and pass 3 vectors with the x,y,z locations of the vertices.
Here is yet another way to plot the cube, if you know only the vertices, and the vertex order is possibly random:
cube1=alphaShape(V); % fit a polyhedron around the vertices
figure; plot(cube1); % plot polyhedron
axis equal; xlabel('X'); ylabel('Y'); zlabel('Z')
With alphaShape(), you do not get an array of vertex numbers for the faces.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!