Problem 60979. Mesh the cube
Problem statement : mesh the cube with quadranglar / squared faces
An cube / regular hexahedron is a regular polyhedron with 8 vertices and 6 squared / quadrangular faces. It is also one of the five well known platonic solids.
A quadrangular mesh F (stands for faces here) is simply a N x 4 matrix of positive integers where each row contains the vertex indices of squared faces, and where N is the number of faces.
Your task here is to mesh this cube. To do so, you will list the squares/rows in a matrix of faces, F. You will also be careful to always keep the faces coherently / consistently oriented (all clockwise or all counterclockwise : square [1, 2, 3, 4] and [4, 3, 2, 1] are distinct).
On the other hand [1, 2, 3, 4], [2, 3, 4, 1], [3, 4, 1, 2] and [4, 1, 2, 3] are one same unique square.
The row order of the faces in the list doesn't matter.
Edit / update
Faces orientation not taken into account anymore, because of too many possible cases to check in the tests (!)
Example
The first square (Z > 0) here can be [1, 2, 3, 4] if counterclockwise oriented (normals outward).
Forbidden functions / expressions
- regexp
- assignin
- str2num
- echo
See also
Solution Stats
Problem Comments
-
1 Comment
Nicolas Douillet
on 23 Jul 2025
To visualize and check your result, you can do for instance :
for n = 1:size(F,1)
fill3(V(F(n,:),1),V(F(n,:),2),V(F(n,:),3),[0 1 1]), hold on;
end
axis equal;
alpha(0.5);
Solution Comments
Show commentsProblem Recent Solvers22
Suggested Problems
-
22 Solvers
More from this Author42
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!