# Creating a 3D mesh plot and exporting it to an STL file for 3D printing

GROUPS:
 Phalgun Lolur 5 Votes Hello all,I've been trying to create a 3 D plot from my data. I have my X,Y, Z matrices, where Z = f(X,Y). I have my matrices in excel, which I've imported to Mathematica.A little bit of background here - I've not used Mathematica before. But fairly comfortable with Matlab. I'm trying to use Mathematica because it lets me create plots where I can create 3D models with tubes as opposed to surfaces on Matlab. My final goal is to create a 3D surface and export it as an STL file so that it can be printed using a 3D printer.Here's an image of what I'm trying to make:I'd appreciate it if someone can help me with this.Thanks.
4 years ago
6 Replies
 Vitaliy Kaurov 9 Votes Generally it is always a good idea to provide working code so that others have a starting point.All this is very easy to do in Mathematica. No need to use Excel either, because I see that you build analytic surfaces that can be sampled in Mathematica too. First I recommend reading Notes on 3D printing by Henry Segerman who did a lot of work on the subject and published a paper.A rather quick summary for you about specifically your problem. Here is the code: f[u_, v_] := {u, v, u^2 - v^2}; scale = 40; radius = 0.75; gridSteps = 10; curvesU = Table[scale*f[u, i], {i, -1, 1, 2/gridSteps}]; curvesV = Table[scale*f[j, v], {j, -1, 1, 2/gridSteps}]; tubesU = ParametricPlot3D[curvesU, {u, -1, 1},     PlotStyle -> Tube[radius], PlotRange -> All]; tubesV = ParametricPlot3D[curvesV, {v, -1, 1},    PlotStyle -> Tube[radius], PlotRange -> All];corners =   Graphics3D[   Table[Sphere[scale f[i, j], radius], {i, -1, 1, 2}, {j, -1, 1, 2}]];output = Show[tubesU, tubesV, corners]Export["MathematicaParametricSurface.stl", output]Here is how the resulting STL file is viewed in an independent STL viewing program - for example MeshLab which is free:And here is final 3D printed result you can find in Shapeways store:Now sometimes you will wish to plot surfaces as they are, not as meshes. Here is a simple example.model = RevolutionPlot3D[{Sin[t] + Sin[5 t]/10,    Cos[t] + Cos[5 t]/10}, {t, 0, Pi},   RegionFunction -> (Sin[5 (#4 + #5)] > 0 &), Mesh -> None,   BoundaryStyle -> Black, PlotStyle -> Thickness[.1]]Export["model.stl", model];Import[%]Now further very useful links:
4 years ago
 Dear Vitaliy,I have already looked into the paper by Segermen, actually. He uses a parametric funtion to get his mesh. What I'm trying to do is generate a mesh plot from my data. I don't have a functional form to it. That is something I'm unable to do, which is also why I couldn't supply any code to this query. I would appreciate it if you can help me in this direction.Thanks.
4 years ago
 Vitaliy Kaurov 1 Vote So the plot you provided is not built from your data? Also what kind of data you have? Did you try to visualize them in Mathematica? - we have a lot of functions for that - ListPlot3D and similar. Without more infirmation it is very hard to move ahead.