CREATEDODECAHEDRON Create a 3D mesh representing a dodecahedron. [V, E, F] = createDodecahedron; Create a 3D mesh representing a dodecahedron V is the 20-by-3 array of vertex coordinates E is the 30-by-2 array of edge vertex indices F is the 12-by-5 array of face vertex indices [V, F] = createDodecahedron; Returns only the vertices and the face vertex indices. MESH = createDodecahedron; Returns the data as a mesh structure, with fields 'vertices', 'edges' and 'faces'. Example [v, e, f] = createDodecahedron; drawMesh(v, f); Use values given by P. Bourke, see: http://local.wasp.uwa.edu.au/~pbourke/geometry/platonic/ faces are re-oriented to have normals pointing outwards. See also meshes3d, drawMesh createCube, createOctahedron, createIcosahedron, createTetrahedron
0001 function varargout = createDodecahedron() 0002 %CREATEDODECAHEDRON Create a 3D mesh representing a dodecahedron. 0003 % 0004 % [V, E, F] = createDodecahedron; 0005 % Create a 3D mesh representing a dodecahedron 0006 % V is the 20-by-3 array of vertex coordinates 0007 % E is the 30-by-2 array of edge vertex indices 0008 % F is the 12-by-5 array of face vertex indices 0009 % 0010 % [V, F] = createDodecahedron; 0011 % Returns only the vertices and the face vertex indices. 0012 % 0013 % MESH = createDodecahedron; 0014 % Returns the data as a mesh structure, with fields 'vertices', 'edges' 0015 % and 'faces'. 0016 % 0017 % Example 0018 % [v, e, f] = createDodecahedron; 0019 % drawMesh(v, f); 0020 % 0021 % Use values given by P. Bourke, see: 0022 % http://local.wasp.uwa.edu.au/~pbourke/geometry/platonic/ 0023 % faces are re-oriented to have normals pointing outwards. 0024 % 0025 % See also 0026 % meshes3d, drawMesh 0027 % createCube, createOctahedron, createIcosahedron, createTetrahedron 0028 % 0029 0030 % --------- 0031 % author : David Legland 0032 % e-mail: david.legland@inra.fr 0033 % INRA - TPV URPOI - BIA IMASTE 0034 % created the 29/07/2010. 0035 % 0036 0037 % HISTORY 0038 0039 % golden ratio 0040 phi = (1+sqrt(5))/2; 0041 0042 % coordinates pre-computations 0043 b = 1 / phi ; 0044 c = 2 - phi ; 0045 0046 % use values given by P. Bourke, see: 0047 % http://local.wasp.uwa.edu.au/~pbourke/geometry/platonic/ 0048 tmp = [ ... 0049 c 0 1 ; b b b ; 0 1 c ; -b b b ; -c 0 1 ; ... 0050 -c 0 1 ; -b -b b ; 0 -1 c ; b -b b ; c 0 1 ; ... 0051 c 0 -1 ; b -b -b ; 0 -1 -c ; -b -b -b ; -c 0 -1 ; ... 0052 -c 0 -1 ; -b b -b ; 0 1 -c ; b b -b ; c 0 -1 ; ... 0053 0 1 -c ; 0 1 c ; b b b ; 1 c 0 ; b b -b ; ... 0054 0 1 c ; 0 1 -c ; -b b -b ; -1 c 0 ; -b b b ; ... 0055 0 -1 -c ; 0 -1 c ; -b -b b ; -1 -c 0 ; -b -b -b ; ... 0056 0 -1 c ; 0 -1 -c ; b -b -b ; 1 -c 0 ; b -b b ; ... 0057 1 c 0 ; b b b ; c 0 1 ; b -b b ; 1 -c 0 ; ... 0058 1 -c 0 ; b -b -b ; c 0 -1 ; b b -b ; 1 c 0 ; ... 0059 -1 c 0 ; -b b -b ; -c 0 -1 ; -b -b -b ; -1 -c 0 ; ... 0060 -1 -c 0 ; -b -b b ; -c 0 1 ; -b b b ; -1 c 0 ; ... 0061 ]; 0062 0063 % extract coordinates of unique vertices 0064 [verts, M, N] = unique(tmp, 'rows', 'first'); %#ok<ASGLU> 0065 0066 % compute indices of face vertices, put result in a 12-by-5 index array 0067 ind0 = reshape((1:60), [5 12])'; 0068 faces = N(ind0); 0069 0070 % extract edges from faces 0071 edges = [reshape(faces(:, 1:5), [60 1]) reshape(faces(:, [2:5 1]), [60 1])]; 0072 edges = unique(sort(edges, 2), 'rows'); 0073 0074 0075 % format output 0076 varargout = formatMeshOutput(nargout, verts, edges, faces);