mesh_shrink - implode vertices of mesh by specific distance FV = mesh_shrink(FV,origin,dist) FV is a struct with fields: FV.vertices - Nx3 matrix of Cartesian vertex coordindates (X,Y,Z) FV.faces - Mx3 matrix of triangulation of FV.vertices origin - 1x3 row vector, usually (0,0,0) dist - how far to implode the mesh toward the origin; this distance is relative to current distance from the origin, not the total distance from the origin.
0001 function [FV] = mesh_shrink(FV,origin,dist), 0002 0003 % mesh_shrink - implode vertices of mesh by specific distance 0004 % 0005 % FV = mesh_shrink(FV,origin,dist) 0006 % 0007 % FV is a struct with fields: 0008 % 0009 % FV.vertices - Nx3 matrix of Cartesian vertex coordindates (X,Y,Z) 0010 % FV.faces - Mx3 matrix of triangulation of FV.vertices 0011 % 0012 % origin - 1x3 row vector, usually (0,0,0) 0013 % 0014 % dist - how far to implode the mesh toward the origin; 0015 % this distance is relative to current distance from 0016 % the origin, not the total distance from the origin. 0017 % 0018 0019 % $Revision: 1.1 $ $Date: 2004/11/12 01:32:35 $ 0020 0021 % Licence: GNU GPL, no implied or express warranties 0022 % History: 10/2002, Darren.Weber_at_radiology.ucsf.edu 0023 % 0024 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0025 0026 0027 xo = origin(1); yo = origin(2); zo = origin(3); 0028 0029 Nvert = size(FV.vertices,1); 0030 0031 fprintf('...mesh implosion...'); tic; 0032 0033 for v = 1:Nvert, 0034 0035 x = FV.vertices(v,1); 0036 y = FV.vertices(v,2); 0037 z = FV.vertices(v,3); 0038 0039 % Find direction cosines for line from centre to vertex 0040 d = sqrt( (x-xo)^2 + (y-yo)^2 + (z-zo)^2 ); 0041 0042 l = (x-xo)/d; % cos alpha 0043 m = (y-yo)/d; % cos beta 0044 n = (z-zo)/d; % cos gamma 0045 0046 % now decrease d by dist 0047 d = d - dist; 0048 0049 % locate vertex at this new distance 0050 x = (l * d) + xo; 0051 y = (m * d) + yo; 0052 z = (n * d) + zo; 0053 0054 FV.vertices(v,:) = [ x y z ]; 0055 end 0056 0057 t = toc; fprintf('...done (%5.2f sec)\n',t); 0058 0059 return 0060