Code covered by the BSD License

# punctureSurface

### Paul Kassebaum (view profile)

18 Oct 2013 (Updated )

Create a 3D printable meshed surface

tPunctureSurface.m
% tPunctureSurface.m
%
% Test regimen for punctureSurface.m

% Copyright 2013 The MathWorks, Inc.

k = 7;
n = 2*k + 1;
x = linspace(-1,1,n);
thickness = 0.05*max(x);
[x,y] = meshgrid(x);
z = (40/51/0.9)*(max(x(:))-min(x(:)))*membrane(1,k);
h = surf(x,y,z);
set(h,'visible','off');
p = surf2patch(h);
sub = [1:n-1,repmat(n,1,n-1),n:-1:2,ones(1,n-1)];
boundVert = sub2ind(size(z),...
sub,...
circshift(sub,[0 n-1]));
boundVert = [boundVert,boundVert(1)];
s = punctureSurface(p, boundVert, 0.5, thickness);
ps = patch(s);
set(ps, ...
'EdgeColor','none', ...
'FaceColor',[0.9 0.2 0.2], ...
'FaceLighting','phong', ...
'AmbientStrength',0.3, ...
'DiffuseStrength',0.6, ...
'Clipping','off',...
'BackFaceLighting','lit', ...
'SpecularStrength',1, ...
'SpecularColorReflectance',1, ...
'SpecularExponent',7);
l1 = light('Position',[40 100 20], ...
'Style','local', ...
'Color',[0 0.8 0.8]);
l2 = light('Position',[.5 -1 .4], ...
'Color',[0.8 0.8 0]);
axis vis3d;
axis equal;

dt = delaunayTriangulation(x(:),y(:));
fv.faces = dt.ConnectivityList;
xy = dt.Points;
fv.vertices = [xy(:,1) xy(:,2) z(:)];
boundEdge = dt.freeBoundary;
boundVert = [boundEdge(:,1);boundEdge(1,1)];
boundVert = fliplr(boundVert);
ss = punctureSurface(fv, boundVert, 0.5, thickness);
figure;
pss = patch(ss);
axis vis3d;
axis equal;
set(pss, ...
'EdgeColor','none', ...
'FaceColor',[0.9 0.2 0.2], ...
'FaceLighting','phong', ...
'AmbientStrength',0.3, ...
'DiffuseStrength',0.6, ...
'Clipping','off',...
'BackFaceLighting','lit', ...
'SpecularStrength',1, ...
'SpecularColorReflectance',1, ...
'SpecularExponent',7);
l1 = light('Position',[40 100 20], ...
'Style','local', ...
'Color',[0 0.8 0.8]);
l2 = light('Position',[.5 -1 .4], ...
'Color',[0.8 0.8 0]);

n = 15;
x = linspace(-1,1,n);
thickness = 0.05*max(x);
[x,y] = meshgrid(x);
z = abs(cos(complex(x,y)));
figure;
h = surf(x,y,z);
set(h,'visible','off');
p = surf2patch(h);
sub = [1:n-1,repmat(n,1,n-1),n:-1:2,ones(1,n-1)];
boundVert = sub2ind(size(z),...
sub,...
circshift(sub,[0 n-1]));
boundVert = [boundVert,boundVert(1)];
s = punctureSurface(p, boundVert, 0.5, thickness);
zeta = complex(s.vertices(:,1),s.vertices(:,2));
w = sin(zeta);
u = real(w);
v = imag(w);
s.vertices = [u,v,s.vertices(:,3)];
ps = patch(s);
axis vis3d;
axis equal;
set(gca,'visible','off');
set(ps, ...
'EdgeColor','none', ...
'FaceColor',[0.9 0.2 0.2], ...
'FaceLighting','phong', ...
'AmbientStrength',0.3, ...
'DiffuseStrength',0.6, ...
'Clipping','off',...
'BackFaceLighting','lit', ...
'SpecularStrength',1, ...
'SpecularColorReflectance',1, ...
'SpecularExponent',7);
l1 = light('Position',[40 100 20], ...
'Style','local', ...
'Color',[0 0.8 0.8]);
l2 = light('Position',[.5 -1 .4], ...
'Color',[0.8 0.8 0]);