# 3D Printing Plot3D

I would like to prepare 3D plots for printing in a 3D printer. The printer does not print lines or surfaces because they have zero thickness. So I have to replace them with Cylinders. Is there way to make Mathematica use Cylinder (and Spheres at each intersection) in presenting the mesh? Perhaps by specifying MeshFunctions->f[Cylinder[],Sphere[]]? I thought I'd start with Plot3D[Sin[x + y^2], {x, -3, 3}, {y, -2, 2}, MeshFunctions -> (Sphere[{#1, #2, #3}, .05]) &] but that went over like a lead balloon.

You can use {style, Tube[radius]} as a styling directive to set MeshStyle:

 Plot3D[Sin[x + y^2], {x, -3, 3}, {y, -2, 2},
PlotPoints -> 90,
ImageSize -> Large,
PlotStyle -> FaceForm[],
MeshFunctions -> {# &, #2 &},
Mesh -> 10,
MeshStyle -> {{Red, Tube[.05]}},
BoundaryStyle -> {Blue, Tube[.05]},


• Nice and economical! Many thanks. Commented Mar 10, 2022 at 12:25
• @NicholasG, my pleasure. Thank you for the accept.
– kglr
Commented Mar 10, 2022 at 12:42

Update:

This will create a mesh or net, without the surface, which is more in line with the OP's desires (see comment below):

Plot3D[Sin[x + y^2], {x, -3, 3}, {y, -2, 2}, PlotStyle -> FaceForm[None]] /.
Line[p_] :> {Sphere[p, .03], Tube[p, 0.03]}


I can't test 3D printing, but maybe Tube could be used to replace Line:

Plot3D[Sin[x + y^2], {x, -3, 3}, {y, -2, 2}] /. Line[p_] :> Tube[p, 0.02]


Adjust the radius 0.02 to suit printing needs, assuming Tube is rendered properly.

One can use Cylinder like this:

Plot3D[Sin[x + y^2], {x, -3, 3}, {y, -2, 2}] /.
Line[p_] :> (Cylinder[#, 0.02] & /@ Partition[p, 2, 1])


The ends of adjacent cylinders won't match exactly as can be seen below. I don't know if that would need fixing before printing. (This does not happen with Tube.)

• Nice. Replace your code with Plot3D[Sin[x + y^2], {x, -3, 3}, {y, -2, 2}, PlotStyle -> FaceForm[None]] /. Line[p_] :> {Sphere[p, .03], Tube[p, 0.03]} so as to take care of the joints by putting Speres at the joints and I'll accept it! Commented Nov 26, 2016 at 18:30
• @NicholasG Done. BTW, are there problems with the joints using Tube? I can see it happening with Cylinder, but I didn't expect it with Tube. Commented Nov 26, 2016 at 18:41
• @NicholasG That close-up is of the cylinders. With Tube, I see no wedges: i.sstatic.net/HZuzf.png Commented Nov 26, 2016 at 19:18
• I thought that the problem would wedge-form gaps produced on the oblique side of angles and putting spheres in there would cure the problem. I thought there were such gaps in the intersection that is in the foreground in your close-up. But it turns out I was wrong, the tubes do not leave gaps in bends. But the spheres might still help at the ends. Commented Nov 26, 2016 at 19:32