Home > matGeom > meshes3d > createMengerSponge.m

createMengerSponge

PURPOSE ^

CREATEMENGERSPONGE Create a cube with an inside cross removed.

SYNOPSIS ^

function varargout = createMengerSponge()

DESCRIPTION ^

CREATEMENGERSPONGE Create a cube with an inside cross removed.

   [n, e, f] = createMengerSponge;
   Main use is to test possibility of drawing polyhedra with complex faces
   (polygonal faces with holes)

   Example
   [n, e, f] = createMengerSponge;
   drawMesh(n, f);
   
   See also
   meshes3d, drawMesh

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function varargout = createMengerSponge()
0002 %CREATEMENGERSPONGE Create a cube with an inside cross removed.
0003 %
0004 %   [n, e, f] = createMengerSponge;
0005 %   Main use is to test possibility of drawing polyhedra with complex faces
0006 %   (polygonal faces with holes)
0007 %
0008 %   Example
0009 %   [n, e, f] = createMengerSponge;
0010 %   drawMesh(n, f);
0011 %
0012 %   See also
0013 %   meshes3d, drawMesh
0014 %
0015 
0016 % ------
0017 % Author: David Legland
0018 % e-mail: david.legland@inra.fr
0019 % Created: 2007-10-18
0020 % Copyright 2007 INRA - BIA PV Nantes - MIAJ Jouy-en-Josas.
0021 
0022 %   HISTORY
0023 %   2008-10-17 finishes implementation
0024 
0025 nodes =[...
0026     ... % main cube corners (1->8)
0027     0 0 0; ...
0028     3 0 0; ...
0029     0 3 0; ...
0030     3 3 0; ...
0031     0 0 3; ...
0032     3 0 3; ...
0033     0 3 3; ...
0034     3 3 3; ...
0035     ... % outer cube inner face corners
0036     1 1 0; ... % face z=0 (9->12)
0037     2 1 0; ...
0038     1 2 0; ...
0039     2 2 0; ...
0040     1 1 3; ... % face z=3 (13->16)
0041     2 1 3; ...
0042     1 2 3; ...
0043     2 2 3; ...
0044     1 0 1; ... % face y=0 (17->20)
0045     2 0 1; ...
0046     1 0 2; ...
0047     2 0 2; ...
0048     1 3 1; ... % face y=3 (21->24)
0049     2 3 1; ...
0050     1 3 2; ...
0051     2 3 2; ...
0052     0 1 1; ... % face x=0 (25->28)
0053     0 2 1; ...
0054     0 1 2; ...
0055     0 2 2; ...
0056     3 1 1; ... % face x=3 (29->32)
0057     3 2 1; ...
0058     3 1 2; ...
0059     3 2 2; ...
0060     ... % inner cube corners  (33->40)
0061     1 1 1; ...
0062     2 1 1; ...
0063     1 2 1; ...
0064     2 2 1; ...
0065     1 1 2; ...
0066     2 1 2; ...
0067     1 2 2; ...
0068     2 2 2; ...
0069     ];
0070     
0071 edges = [...
0072     1 2;1 3;2 4;3 4;5 6;5 7;6 8;7 8;1 5;2 6;3 7;4 8;... % outer cube
0073     9 10;9 11;10 12;11 12;13 14;13 15;14 16;15 16; ... 
0074     17 18;17 19;18 20;19 20; 21 22;21 23;22 24;23 24; ...
0075     25 26;25 27;26 28;27 28; 29 30;29 31;30 32;31 32; ...
0076     33 34;33 35;34 36;35 36; 37 38;37 39;38 40;39 40; ... % inner cube
0077     33 37;34 38;35 39;36 40; ...
0078      9 33;10 34;11 35;12 36; ... % parallel to xy
0079     13 37;14 38;15 39;16 40; ...
0080     17 33;18 34;19 37;20 38; ... % parallel to yz
0081     21 35;22 36;23 39;24 40; ...
0082     25 33;26 35;27 37;28 39; ... % parallel to xz
0083     29 34;30 36;31 38;32 40; ...
0084     ];
0085 
0086 % Alternative definition for faces:
0087 %     [1 2 4 3 NaN 9  11 12 10], ...
0088 %     [5 6 8 7 NaN 13 15 16 14], ...
0089 %     [1 5 7 3 NaN 25 26 28 27], ....
0090 %     [2 6 8 4 NaN 29 30 32 31], ...
0091 %     [1 2 6 5 NaN 17 18 20 19], ...
0092 %     [3 4 8 7 NaN 21 22 24 23], ...
0093 
0094 faces = {...
0095     ... % 6 square faces with a square hole
0096     [1 2 4 3 1 9  11 12 10  9], ... 
0097     [5 6 8 7 5 13 15 16 14 13], ...
0098     [1 5 7 3 1 25 26 28 27 25], ....
0099     [2 6 8 4 2 29 30 32 31 29], ...
0100     [1 2 6 5 1 17 18 20 19 17], ...
0101     [3 4 8 7 3 21 22 24 23 21], ...
0102     ... % faces orthogonal to XY plane, parallel to Oz axis
0103     [ 9 10 34 33], [ 9 11 35 33], [10 12 36 34], [11 12 36 35], ... 
0104     [13 14 38 37], [13 15 39 37], [14 16 40 38], [15 16 40 39], ...
0105     ... % faces orthogonal to YZ plane, parallel to Oy axis
0106     [17 18 34 33], [17 19 37 33], [18 20 38 34], [19 20 38 37], ...
0107     [21 22 36 35], [21 23 39 35], [22 24 40 36], [23 24 40 39], ...
0108     ...% faces orthogonal to the YZ plane, parallel to Ox axis
0109     [25 33 35 26], [25 33 37 27], [26 35 39 28], [27 37 39 28], ...
0110     [29 30 36 34], [29 31 38 34], [30 32 40 36], [31 32 40 38], ...
0111     };
0112 
0113 % format output
0114 varargout = formatMeshOutput(nargout, nodes, edges, faces);

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