Filter löschen
Filter löschen

Identifying all elements and their nodal coordinates given all possible nodes

8 Ansichten (letzte 30 Tage)
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?

Antworten (2)

Matt J
Matt J am 29 Mai 2024
Bearbeitet: Matt J am 29 Mai 2024
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
V = 8x3
5 6 7 5 6 8 5 7 7 5 7 8 6 6 7 6 6 8 6 7 7 6 7 8
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
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{:}
ans = 4x3
5 6 7 5 6 8 5 7 7 5 7 8
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
ans = 4x3
6 6 7 6 6 8 6 7 7 6 7 8
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
ans = 4x3
5 6 7 5 6 8 6 6 7 6 6 8
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
ans = 4x3
5 7 7 5 7 8 6 7 7 6 7 8
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
ans = 4x3
5 6 7 5 7 7 6 6 7 6 7 7
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
ans = 4x3
5 6 8 5 7 8 6 6 8 6 7 8
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>

William Rose
William Rose am 29 Mai 2024
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.

Kategorien

Mehr zu Bounding Regions finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by