Home > matGeom > meshes3d > createStellatedMesh.m

createStellatedMesh

PURPOSE ^

CREATESTELLATEDMESH Replaces each face of a mesh by a pyramid.

SYNOPSIS ^

function varargout = createStellatedMesh(vertices, faces, varargin)

DESCRIPTION ^

CREATESTELLATEDMESH  Replaces each face of a mesh by a pyramid.

   [V2, F2] = createStellatedMesh(V, F)

   Example
     [v, f] = createCube
     [v2, f2] = createStellatedMesh(v, f);
     figure; drawMesh(v2, f2); axis equal; view(3);

   See also
     meshes3d, drawMesh

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function varargout = createStellatedMesh(vertices, faces, varargin)
0002 %CREATESTELLATEDMESH  Replaces each face of a mesh by a pyramid.
0003 %
0004 %   [V2, F2] = createStellatedMesh(V, F)
0005 %
0006 %   Example
0007 %     [v, f] = createCube
0008 %     [v2, f2] = createStellatedMesh(v, f);
0009 %     figure; drawMesh(v2, f2); axis equal; view(3);
0010 %
0011 %   See also
0012 %     meshes3d, drawMesh
0013  
0014 % ------
0015 % Author: David Legland
0016 % e-mail: david.legland@inra.fr
0017 % Created: 2018-11-27,    using Matlab 9.5.0.944444 (R2018b)
0018 % Copyright 2018 INRA - Cepia Software Platform.
0019 
0020 % properties of mesh
0021 nVertices = size(vertices, 1);
0022 nFaces = size(faces, 1);
0023 
0024 % shift coefficients for computing new vertices
0025 coeffs = ones(nFaces, 1);
0026 if ~isempty(varargin)
0027     var1 = varargin{1};
0028     if isnumeric(var1) && isscalar(var1)
0029         coeffs = coeffs * var1;
0030     elseif isnumeric(var1) && length(var1) == nFaces
0031         coeffs = var1(:);
0032     else
0033         error('Coefficients must be either a scalar or a nFaces-by-1 array');
0034     end
0035 end
0036 
0037 % supporting line of new vertices
0038 fc = meshFaceCentroids(vertices, faces);
0039 fn = meshFaceNormals(vertices, faces);
0040 
0041 % position of new vertices
0042 nv = fc + bsxfun(@times, fn, coeffs);
0043 
0044 % create data for new mesh
0045 v2 = [vertices ; nv];
0046 f2 = zeros(nFaces * 3, 3);
0047 indF = 0;
0048 
0049 % iterate over faces
0050 for iFace = 1:nFaces
0051     % indices of vertices of current face
0052     face = meshFace(faces, iFace);
0053 %     face = faces(iFace, :);
0054 
0055     % iterate over edges to create new triangular faces
0056     for ivf = 1:length(face)
0057         ind1 = face(ivf);
0058         ind2 = face(mod(ivf, length(face)) + 1);
0059         
0060         indF = indF + 1;
0061         f2(indF, :) = [ind1 ind2 iFace+nVertices];
0062     end
0063 end
0064 
0065 % format output
0066 varargout = formatMeshOutput(nargout, v2, f2);

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