{"id":4953,"date":"2013-12-06T09:00:55","date_gmt":"2013-12-06T14:00:55","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/?p=4953"},"modified":"2013-12-06T11:12:50","modified_gmt":"2013-12-06T16:12:50","slug":"surface-to-solid","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2013\/12\/06\/surface-to-solid\/","title":{"rendered":"Surface To Solid"},"content":{"rendered":"\r\n\r\n<div class=\"content\"><p><a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/15007\">Jiro<\/a>'s pick this week is <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/42876-surf2solid-make-a-solid-volume-from-a-surface-for-3d-printing\"><tt>surf2solid<\/tt><\/a> by <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/43596\">Sven<\/a>.<\/p><p>Sven is no stranger to Pick of the Week. His <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/37856-inpolyhedron-are-points-inside-a-triangulated-volume-\"><tt>inpolyhedron<\/tt><\/a> was <a href=\"https:\/\/blogs.mathworks.com\/pick\/2013\/09\/06\/inpolyhedron\/\">Picked<\/a> by <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/answers\/contributors\/3208495\">Sean<\/a> recently, and he's also active in other areas of MATLAB Central. In fact, this entry was inspired by a post written by my colleague Paul on <a title=\"https:\/\/blogs.mathworks.com\/community\/2013\/06\/20\/paul-prints-the-l-shaped-membrane\/ (link no longer works)\">\"Printing the 3D L-Shaped Membrane\"<\/a>.<\/p><p><a href=\"http:\/\/en.wikipedia.org\/wiki\/3D_printing\">3D Printing<\/a> allows you to easily create 3D objects from a digital model, such as models created in MATLAB. People are already using MATLAB for 3D printing, and we've written about it a few times, including the post above by Paul, as well as <a href=\"https:\/\/blogs.mathworks.com\/community\/2013\/06\/13\/printing-math\/\">\"Printing Math\"<\/a> and <a href=\"https:\/\/blogs.mathworks.com\/community\/2013\/07\/09\/anamorphic-3d-printing\/\">\"Anamorphic 3D Printing\"<\/a>.<\/p><p>In order to create a 3D object, we can't print a surface which has no thickness. Paul's post above talks about the process of adding that thickness. Sven took some of those techniques and created <tt>surf2solid<\/tt>. It's very easy to use with very good instructions (help). You simply provide the data that you would normally pass into <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/surf.html\"><tt>surf<\/tt><\/a> or <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/patch.html\"><tt>patch<\/tt><\/a>, and optionally specify the thickness (for a uniform thickness), the elevation (for a block with a flat bottom), and the triangulation method.<\/p><p>Since I don't have one of those fancy 3D printing machines, I'll show an animation of a vibrating (thick) membrane. This is a modification of a shipping demo called <tt>vibes<\/tt>.<\/p><pre class=\"codeinput\"><span class=\"comment\">% Eigenvalues<\/span>\r\nlambda = [9.6397238445, 15.19725192, 2*pi^2, <span class=\"keyword\">...<\/span>\r\n    29.5214811, 31.9126360, 41.4745099, 44.948488, <span class=\"keyword\">...<\/span>\r\n    5*pi^2, 5*pi^2, 56.709610, 65.376535, 71.057755];\r\n\r\n<span class=\"comment\">% Eigenfunctions<\/span>\r\n<span class=\"keyword\">for<\/span> k = 1:12\r\n    L{k} = membrane(k);\r\n<span class=\"keyword\">end<\/span>\r\n\r\n<span class=\"comment\">% Get coefficients from eigenfunctions<\/span>\r\n<span class=\"keyword\">for<\/span> k = 1:12\r\n    c(k) = L{k}(25,23)\/3;\r\n<span class=\"keyword\">end<\/span>\r\n\r\n<span class=\"comment\">% Construct solids for animation<\/span>\r\nS = struct(<span class=\"string\">'faces'<\/span>,cell(1,500),<span class=\"string\">'vertices'<\/span>,cell(1,500));\r\nx = (-15:15)\/15;\r\nt = 0;\r\n<span class=\"keyword\">for<\/span> id = 1:length(S)\r\n    <span class=\"comment\">% Coefficients<\/span>\r\n    t = t + 0.02; <span class=\"comment\">% increment time<\/span>\r\n    s = c.*sin(sqrt(lambda)*t);\r\n\r\n    <span class=\"comment\">% Amplitude<\/span>\r\n    A = zeros(size(L{1}));\r\n    <span class=\"keyword\">for<\/span> k = 1:12\r\n        A = A + s(k)*L{k};\r\n    <span class=\"keyword\">end<\/span>\r\n\r\n    <span class=\"comment\">% Convert SURF data to SOLID data<\/span>\r\n    S(id) = surf2solid(x,x,A,<span class=\"string\">'thickness'<\/span>,-0.1);\r\n<span class=\"keyword\">end<\/span>\r\n\r\n<span class=\"comment\">% Create patch and modify view<\/span>\r\npHandle = patch(S(1),<span class=\"string\">'EdgeColor'<\/span>,<span class=\"string\">'r'<\/span>);\r\nview(3)\r\naxis([-1 1 -1 1 -.5 1])\r\naxis <span class=\"string\">off<\/span>\r\n\r\n<span class=\"comment\">% Animate<\/span>\r\n<span class=\"keyword\">for<\/span> id = 1:length(S)\r\n    set(pHandle,<span class=\"string\">'Faces'<\/span>,S(id).faces,<span class=\"string\">'Vertices'<\/span>,S(id).vertices);\r\n    drawnow\r\n<span class=\"keyword\">end<\/span>\r\n<\/pre><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/jiro\/potw_surf2solid\/wave_animation.gif\" alt=\"\"> <\/p><p><b>Comments<\/b><\/p><p>Let us know what you think <a href=\"https:\/\/blogs.mathworks.com\/pick\/?p=4953#respond\">here<\/a> or leave a <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/42876-surf2solid-make-a-solid-volume-from-a-surface-for-3d-printing#comments\">comment<\/a> for Sven.<\/p><script language=\"JavaScript\"> <!-- \r\n    function grabCode_0eff331ec0a3483c9f108e271b7ce92f() {\r\n        \/\/ Remember the title so we can use it in the new page\r\n        title = document.title;\r\n\r\n        \/\/ Break up these strings so that their presence\r\n        \/\/ in the Javascript doesn't mess up the search for\r\n        \/\/ the MATLAB code.\r\n        t1='0eff331ec0a3483c9f108e271b7ce92f ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 0eff331ec0a3483c9f108e271b7ce92f';\r\n    \r\n        b=document.getElementsByTagName('body')[0];\r\n        i1=b.innerHTML.indexOf(t1)+t1.length;\r\n        i2=b.innerHTML.indexOf(t2);\r\n \r\n        code_string = b.innerHTML.substring(i1, i2);\r\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\r\n\r\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \r\n        \/\/ in the XML parser.\r\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\r\n        \/\/ doesn't go ahead and substitute the less-than character. \r\n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\r\n\r\n        copyright = 'Copyright 2013 The MathWorks, Inc.';\r\n\r\n        w = window.open();\r\n        d = w.document;\r\n        d.write('<pre>\\n');\r\n        d.write(code_string);\r\n\r\n        \/\/ Add copyright line at the bottom if specified.\r\n        if (copyright.length > 0) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (copyright.length > 0) {\r\n                d.writeln('% _' + copyright + '_');\r\n            }\r\n        }\r\n\r\n        d.write('<\/pre>\\n');\r\n\r\n        d.title = title + ' (MATLAB code)';\r\n        d.close();\r\n    }   \r\n     --> <\/script><p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\"><br><a href=\"javascript:grabCode_0eff331ec0a3483c9f108e271b7ce92f()\"><span style=\"font-size: x-small;        font-style: italic;\">Get \r\n      the MATLAB code <noscript>(requires JavaScript)<\/noscript><\/span><\/a><br><br>\r\n      Published with MATLAB&reg; R2013b<br><\/p><p class=\"footer\"><br>\r\n      Published with MATLAB&reg; R2013b<br><\/p><\/div><!--\r\n0eff331ec0a3483c9f108e271b7ce92f ##### SOURCE BEGIN #####\r\n%%\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/15007\r\n% Jiro>'s pick this week is\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/42876-surf2solid-make-a-solid-volume-from-a-surface-for-3d-printing |surf2solid|>\r\n% by <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/43596\r\n% Sven>.\r\n%\r\n% Sven is no stranger to Pick of the Week. His\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/37856-inpolyhedron-are-points-inside-a-triangulated-volume-\r\n% |inpolyhedron|> was\r\n% <https:\/\/blogs.mathworks.com\/pick\/2013\/09\/06\/inpolyhedron\/ Picked> by\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/answers\/contributors\/3208495\r\n% Sean> recently, and he's also active in other areas of MATLAB Central. In\r\n% fact, this entry was inspired by a post written by my colleague Paul on\r\n% <https:\/\/blogs.mathworks.com\/community\/2013\/06\/20\/paul-prints-the-l-shaped-membrane\/\r\n% \"Printing the 3D L-Shaped Membrane\">.\r\n%\r\n% <http:\/\/en.wikipedia.org\/wiki\/3D_printing 3D Printing> allows you to\r\n% easily create 3D objects from a digital model, such as models created in\r\n% MATLAB. People are already using MATLAB for 3D printing, and we've\r\n% written about it a few times, including the post above by Paul, as well\r\n% as <https:\/\/blogs.mathworks.com\/community\/2013\/06\/13\/printing-math\/\r\n% \"Printing Math\"> and\r\n% <https:\/\/blogs.mathworks.com\/community\/2013\/07\/09\/anamorphic-3d-printing\/\r\n% \"Anamorphic 3D Printing\">.\r\n%\r\n% In order to create a 3D object, we can't print a surface which has no\r\n% thickness. Paul's post above talks about the process of adding that\r\n% thickness. Sven took some of those techniques and created |surf2solid|.\r\n% It's very easy to use with very good instructions (help). You simply\r\n% provide the data that you would normally pass into\r\n% <https:\/\/www.mathworks.com\/help\/matlab\/ref\/surf.html |surf|> or\r\n% <https:\/\/www.mathworks.com\/help\/matlab\/ref\/patch.html |patch|>, and\r\n% optionally specify the thickness (for a uniform thickness), the elevation\r\n% (for a block with a flat bottom), and the triangulation method.\r\n%\r\n% Since I don't have one of those fancy 3D printing machines, I'll show an\r\n% animation of a vibrating (thick) membrane. This is a modification of a\r\n% shipping demo called |vibes|.\r\n\r\n% Eigenvalues\r\nlambda = [9.6397238445, 15.19725192, 2*pi^2, ...\r\n    29.5214811, 31.9126360, 41.4745099, 44.948488, ...\r\n    5*pi^2, 5*pi^2, 56.709610, 65.376535, 71.057755];\r\n\r\n% Eigenfunctions\r\nfor k = 1:12\r\n    L{k} = membrane(k);\r\nend\r\n\r\n% Get coefficients from eigenfunctions\r\nfor k = 1:12\r\n    c(k) = L{k}(25,23)\/3;\r\nend\r\n\r\n% Construct solids for animation\r\nS = struct('faces',cell(1,500),'vertices',cell(1,500));\r\nx = (-15:15)\/15;\r\nt = 0;\r\nfor id = 1:length(S)\r\n    % Coefficients\r\n    t = t + 0.02; % increment time\r\n    s = c.*sin(sqrt(lambda)*t);\r\n    \r\n    % Amplitude\r\n    A = zeros(size(L{1}));\r\n    for k = 1:12\r\n        A = A + s(k)*L{k};\r\n    end\r\n    \r\n    % Convert SURF data to SOLID data\r\n    S(id) = surf2solid(x,x,A,'thickness',-0.1);\r\nend\r\n\r\n% Create patch and modify view\r\npHandle = patch(S(1),'EdgeColor','r');\r\nview(3)\r\naxis([-1 1 -1 1 -.5 1])\r\naxis off\r\n\r\n% Animate\r\nfor id = 1:length(S)\r\n    set(pHandle,'Faces',S(id).faces,'Vertices',S(id).vertices);\r\n    drawnow\r\nend\r\n\r\n%%\r\n% <<wave_animation.gif>>\r\n\r\n%%\r\n% *Comments*\r\n%\r\n% Let us know what you think\r\n% <https:\/\/blogs.mathworks.com\/pick\/?p=4953#respond here> or leave a\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/42876-surf2solid-make-a-solid-volume-from-a-surface-for-3d-printing#comments\r\n% comment> for Sven.\r\n\r\n##### SOURCE END ##### 0eff331ec0a3483c9f108e271b7ce92f\r\n-->","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/jiro\/potw_surf2solid\/wave_animation.gif\" onError=\"this.style.display ='none';\" \/><\/div><p>\r\n\r\nJiro's pick this week is surf2solid by Sven.Sven is no stranger to Pick of the Week. His inpolyhedron was Picked by Sean recently, and he's also active in other areas of MATLAB Central. In fact,... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2013\/12\/06\/surface-to-solid\/\">read more >><\/a><\/p>","protected":false},"author":35,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[16],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/4953"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/users\/35"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/comments?post=4953"}],"version-history":[{"count":6,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/4953\/revisions"}],"predecessor-version":[{"id":4960,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/4953\/revisions\/4960"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=4953"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=4953"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=4953"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}