Home > matGeom > meshes3d > createIcosahedron.m

createIcosahedron

PURPOSE ^

CREATEICOSAHEDRON Create a 3D mesh representing an Icosahedron.

SYNOPSIS ^

function varargout = createIcosahedron()

DESCRIPTION ^

CREATEICOSAHEDRON Create a 3D mesh representing an Icosahedron.

   MESH = createIcosahedron;
   [V, E, F] = createIcosahedron;
   Create a solid with 12 vertices, and 20 triangular faces. Faces are
   oriented outwards of the mesh.

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

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

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function varargout = createIcosahedron()
0002 %CREATEICOSAHEDRON Create a 3D mesh representing an Icosahedron.
0003 %
0004 %   MESH = createIcosahedron;
0005 %   [V, E, F] = createIcosahedron;
0006 %   Create a solid with 12 vertices, and 20 triangular faces. Faces are
0007 %   oriented outwards of the mesh.
0008 %
0009 %   [V, F] = createIcosahedron;
0010 %   Returns only the vertices and the face vertex indices.
0011 %
0012 %   MESH = createIcosahedron;
0013 %   Returns the data as a mesh structure, with fields 'vertices', 'edges'
0014 %   and 'faces'.
0015 %
0016 %   Example
0017 %     [n, e, f] = createIcosahedron;
0018 %     drawMesh(n, f);
0019 %
0020 %   See also
0021 %   meshes3d, drawMesh
0022 %   createCube, createOctahedron, createDodecahedron, createTetrahedron
0023 %
0024 
0025 %   ---------
0026 %   author: David Legland
0027 %   mail: david.legland@inra.fr
0028 %   INRA - TPV URPOI - BIA IMASTE
0029 %   created the 21/03/2005.
0030 %
0031 
0032 %   HISTORY
0033 %   2007-01-04 remove unused variables
0034 %   2010-12-06 format output, orient normals outwards
0035 
0036 
0037 %% Initialisations
0038 
0039 theta = 2*pi/5;
0040 l = 1/sin(theta/2)/2;
0041 z1 = sqrt(1-l*l);
0042 
0043 t1 = (0:2*pi/5:2*pi*(1-1/5))';
0044 x1 = l*cos(t1);
0045 y1 = l*sin(t1);
0046 
0047 t2 = t1 + 2*pi/10;
0048 x2 = l*cos(t2);
0049 y2 = l*sin(t2);
0050 
0051 h = sqrt(l*l-.5*.5);
0052 z2 = sqrt(3/4 - (l-h)*(l-h));
0053 
0054 
0055 %% Create mesh data
0056 
0057 nodes = [0 0 0;...
0058     [x1 y1 repmat(z1, [5 1])]; ...
0059     [x2 y2 repmat(z1+z2, [5 1])]; ...
0060     0 0 2*z1+z2];
0061 
0062 edges = [...
0063     1 2;1 3;1 4;1 5;1 6; ...
0064     2 3;3 4;4 5;5 6;6 2; ...
0065     2 7;7 3;3 8;8 4;4 9;9 5;5 10;10 6;6 11;11 2; ...
0066     7 8;8 9;9 10;10 11;11 7; ...
0067     7 12;8 12;9 12;10 12;11 12];
0068     
0069 % faces are ordered to have normals pointing outside of the mesh
0070 faces = [...
0071     1 3  2 ; 1 4  3 ; 1  5  4 ;  1  6  5 ;  1 2  6;...
0072     2 3  7 ; 3 4  8 ; 4  5  9 ;  5  6 10 ;  6 2 11;...
0073     7 3  8 ; 8 4  9 ; 9  5 10 ; 10  6 11 ; 11 2  7;...
0074     7 8 12 ; 8 9 12 ; 9 10 12 ; 10 11 12 ; 11 7 12];
0075 
0076 % format output
0077 varargout = formatMeshOutput(nargout, nodes, edges, faces);

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