Home > matGeom > meshes3d > createCube.m

createCube

PURPOSE ^

CREATECUBE Create a 3D mesh representing the unit cube.

SYNOPSIS ^

function varargout = createCube()

DESCRIPTION ^

CREATECUBE Create a 3D mesh representing the unit cube.

   [V, E, F] = createCube 
   Create a unit cube, as a polyhedra representation.
   c has the form [V E F], where V is a 8-by-3 array with vertices
   coordinates, E is a 12-by-2 array containing indices of neighbour
   vertices, and F is a 6-by-4 array containing vertices array of each
   face.

   [V, F] = createCube;
   Returns only the vertices and the face vertex indices.

   MESH = createCube;
   Returns the data as a mesh structure, with fields 'vertices', 'edges'
   and 'faces'.

   Example
   [n, e, f] = createCube;
   drawMesh(n, f);
   
   See also
   meshes3d, drawMesh
   createOctahedron, createTetrahedron, createDodecahedron
   createIcosahedron, createCubeOctahedron

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function varargout = createCube()
0002 %CREATECUBE Create a 3D mesh representing the unit cube.
0003 %
0004 %   [V, E, F] = createCube
0005 %   Create a unit cube, as a polyhedra representation.
0006 %   c has the form [V E F], where V is a 8-by-3 array with vertices
0007 %   coordinates, E is a 12-by-2 array containing indices of neighbour
0008 %   vertices, and F is a 6-by-4 array containing vertices array of each
0009 %   face.
0010 %
0011 %   [V, F] = createCube;
0012 %   Returns only the vertices and the face vertex indices.
0013 %
0014 %   MESH = createCube;
0015 %   Returns the data as a mesh structure, with fields 'vertices', 'edges'
0016 %   and 'faces'.
0017 %
0018 %   Example
0019 %   [n, e, f] = createCube;
0020 %   drawMesh(n, f);
0021 %
0022 %   See also
0023 %   meshes3d, drawMesh
0024 %   createOctahedron, createTetrahedron, createDodecahedron
0025 %   createIcosahedron, createCubeOctahedron
0026 %
0027 
0028 % ---------
0029 % author : David Legland
0030 % e-mail: david.legland@inra.fr
0031 % INRA - TPV URPOI - BIA IMASTE
0032 % created the 10/02/2005.
0033 
0034 
0035 %   HISTORY
0036 %   04/01/2007: remove unused variables
0037 
0038 x0 = 0; dx= 1;
0039 y0 = 0; dy= 1;
0040 z0 = 0; dz= 1;
0041 
0042 nodes = [...
0043     x0 y0 z0; ...
0044     x0+dx y0 z0; ...
0045     x0 y0+dy z0; ...
0046     x0+dx y0+dy z0; ...
0047     x0 y0 z0+dz; ...
0048     x0+dx y0 z0+dz; ...
0049     x0 y0+dy z0+dz; ...
0050     x0+dx y0+dy z0+dz];
0051 
0052 edges = [1 2;1 3;1 5;2 4;2 6;3 4;3 7;4 8;5 6;5 7;6 8;7 8];
0053 
0054 % faces are oriented such that normals point outwards
0055 faces = [1 3 4 2;5 6 8 7;2 4 8 6;1 5 7 3;1 2 6 5;3 7 8 4];
0056 
0057 % format output
0058 varargout = formatMeshOutput(nargout, nodes, edges, faces);

Generated on Wed 16-Feb-2022 15:10:47 by m2html © 2003-2019