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@inrae.fr 0033 % Created: 2010-07-29 0034 % Copyright 2010-2024 INRA - TPV URPOI - BIA IMASTE 0035 0036 % golden ratio 0037 phi = (1+sqrt(5))/2; 0038 0039 % coordinates pre-computations 0040 b = 1 / phi ; 0041 c = 2 - phi ; 0042 0043 % use values given by P. Bourke, see: 0044 % http://local.wasp.uwa.edu.au/~pbourke/geometry/platonic/ 0045 tmp = [ ... 0046 c 0 1 ; b b b ; 0 1 c ; -b b b ; -c 0 1 ; ... 0047 -c 0 1 ; -b -b b ; 0 -1 c ; b -b b ; c 0 1 ; ... 0048 c 0 -1 ; b -b -b ; 0 -1 -c ; -b -b -b ; -c 0 -1 ; ... 0049 -c 0 -1 ; -b b -b ; 0 1 -c ; b b -b ; c 0 -1 ; ... 0050 0 1 -c ; 0 1 c ; b b b ; 1 c 0 ; b b -b ; ... 0051 0 1 c ; 0 1 -c ; -b b -b ; -1 c 0 ; -b b b ; ... 0052 0 -1 -c ; 0 -1 c ; -b -b b ; -1 -c 0 ; -b -b -b ; ... 0053 0 -1 c ; 0 -1 -c ; b -b -b ; 1 -c 0 ; b -b b ; ... 0054 1 c 0 ; b b b ; c 0 1 ; b -b b ; 1 -c 0 ; ... 0055 1 -c 0 ; b -b -b ; c 0 -1 ; b b -b ; 1 c 0 ; ... 0056 -1 c 0 ; -b b -b ; -c 0 -1 ; -b -b -b ; -1 -c 0 ; ... 0057 -1 -c 0 ; -b -b b ; -c 0 1 ; -b b b ; -1 c 0 ; ... 0058 ]; 0059 0060 % extract coordinates of unique vertices 0061 [verts, M, N] = unique(tmp, 'rows', 'first'); %#ok<ASGLU> 0062 0063 % compute indices of face vertices, put result in a 12-by-5 index array 0064 ind0 = reshape((1:60), [5 12])'; 0065 faces = N(ind0); 0066 0067 % extract edges from faces 0068 edges = [reshape(faces(:, 1:5), [60 1]) reshape(faces(:, [2:5 1]), [60 1])]; 0069 edges = unique(sort(edges, 2), 'rows'); 0070 0071 0072 % format output 0073 varargout = formatMeshOutput(nargout, verts, edges, faces);