[node,face,elem]=meshasphere(c0,r,tsize,maxvol) create the surface and tetrahedral mesh of a sphere author: Qianqian Fang, <q.fang at neu.edu> input: c0: center coordinates (x0,y0,z0) of the sphere r: radius of the sphere tsize: maximum surface triangle size on the sphere maxvol: maximu volume of the tetrahedral elements output: node: node coordinates, 3 columns for x, y and z respectively face: integer array with dimensions of NB x 3, each row represents a surface mesh face element elem: integer array with dimensions of NE x 4, each row represents a tetrahedron -- this function is part of iso2mesh toolbox (http://iso2mesh.sf.net)
0001 function [node,face,elem]=meshasphere(c0,r,tsize,maxvol) 0002 % 0003 % [node,face,elem]=meshasphere(c0,r,tsize,maxvol) 0004 % 0005 % create the surface and tetrahedral mesh of a sphere 0006 % 0007 % author: Qianqian Fang, <q.fang at neu.edu> 0008 % 0009 % input: 0010 % c0: center coordinates (x0,y0,z0) of the sphere 0011 % r: radius of the sphere 0012 % tsize: maximum surface triangle size on the sphere 0013 % maxvol: maximu volume of the tetrahedral elements 0014 % 0015 % output: 0016 % node: node coordinates, 3 columns for x, y and z respectively 0017 % face: integer array with dimensions of NB x 3, each row represents 0018 % a surface mesh face element 0019 % elem: integer array with dimensions of NE x 4, each row represents 0020 % a tetrahedron 0021 % 0022 % -- this function is part of iso2mesh toolbox (http://iso2mesh.sf.net) 0023 % 0024 0025 if(nargin<3) 0026 error('you must at least provide c0, r and tsize'); 0027 end 0028 if(nargin==3) 0029 maxvol=tsize*tsize*tsize; 0030 end 0031 if(nargout==3) 0032 [node,face,elem]=meshunitsphere(tsize/r,maxvol/(r*r*r)); 0033 else 0034 [node,face]=meshunitsphere(tsize/r); 0035 end 0036 0037 node=node*r+repmat(c0(:)',size(node,1),1);