3
$\begingroup$

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.

$\endgroup$

2 Answers 2

2
$\begingroup$

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]}, 
  PlotRangePadding -> Scaled[.05]]

enter image description here

$\endgroup$
2
  • $\begingroup$ Nice and economical! Many thanks. $\endgroup$
    – Nicholas G
    Mar 10, 2022 at 12:25
  • $\begingroup$ @NicholasG, my pleasure. Thank you for the accept. $\endgroup$
    – kglr
    Mar 10, 2022 at 12:42
4
$\begingroup$

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]}

Original answer:

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]

Mathematica graphics

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.)

Mathematica graphics

$\endgroup$
4
  • 1
    $\begingroup$ 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! $\endgroup$
    – Nicholas G
    Nov 26, 2016 at 18:30
  • $\begingroup$ @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. $\endgroup$
    – Michael E2
    Nov 26, 2016 at 18:41
  • $\begingroup$ @NicholasG That close-up is of the cylinders. With Tube, I see no wedges: i.stack.imgur.com/HZuzf.png $\endgroup$
    – Michael E2
    Nov 26, 2016 at 19:18
  • $\begingroup$ 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. $\endgroup$
    – Nicholas G
    Nov 26, 2016 at 19:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.