Problem 60978. Mesh the octahedron
Problem statement
An octahedron is a regular polyhedron with 6 vertices and 8 triangular faces. It is also one of the five well known platonic solids.
A triangulated mesh -or a triangulation- is simply a N x 3 matrix of positive integers where each row contains the vertex indices of a triangle, and where N is the number of triangles.
Your task here is to mesh this octahedron. To do so, you will list the triangles/rows in a matrix of triangles, T. You will also be careful to always keep the triangles / faces coherently / consistently oriented (all clockwise or all counterclockwise : triangles [1, 2, 3] and [3, 2, 1] are distinct).
On the other hand [1, 2, 3], [2, 3, 1] and [3, 1, 2] are one same unique triangle.
The row order of the triangles in the list doesn't matter.
Edit / update
Triangles orientation not taken into account anymore, because of too many possible cases to check in the tests (!)
Example
The first triangle (X > 0, Y > 0, and Z > 0) here can be [1, 2, 5] if counterclockwise oriented (normals are outward oriented).
Forbidden functions / expressions
- regexp
- assignin
- str2num
- echo
See also
Solution Stats
Problem Comments
-
1 Comment
Nicolas Douillet
on 23 Jul 2025 at 16:06
To visualize and check your result you can do for instance :
trisurf(T,V(:,1),V(:,2),V(:,3));
colormap([0 1 1]);
axis equal, alpha(0.5);
Solution Comments
Show commentsProblem Recent Solvers12
Suggested Problems
-
12 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!