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개)
Matt J
2024년 5월 29일
편집: Matt J
2024년 5월 29일
Assuming the cube is unrotated,
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]+[5,6,7] %cube vertices
vmin=min(V);
vmax=max(V);
Faces=cell(2,3);
for i=1:3
idx=vmin(i)==V(:,i);
Faces{1,i}=V(idx,:);
idx=vmax(i)==V(:,i);
Faces{2,i}=V(idx,:);
end
Faces{:}
댓글 수: 0
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!