15
$\begingroup$

My code:

Plot3D[{(2*x*y)/(x^2 + y^2)}, {x, -2, 2}, {y, -2, 2}]

Output:

enter image description here

And now I can export this to STL by using the export STL command, however, when I try to print this on the MakerBot 3D printer there is a problem because the width of the graph is too thin. I need to increase the thickness of the width of the graph, can I do this in Mathematica?

$\endgroup$
3
  • 1
    $\begingroup$ Try with RegionPlot3D[] $\endgroup$ Commented Nov 24, 2013 at 1:49
  • $\begingroup$ I'm confused by your terminology. What do mean by "width" and "thickness"? I have no idea what dimension "width" refers to, and as for "thickness", a surface it infinitesimally thin by definition. $\endgroup$
    – m_goldberg
    Commented Nov 24, 2013 at 3:49
  • $\begingroup$ Here's an article about 3D printing from Mathematica... there are some tricks to take note of. segerman.org/3d_printing_notes.html $\endgroup$
    – bill s
    Commented Nov 24, 2013 at 4:20

4 Answers 4

16
$\begingroup$

Try this:

Plot3D[{(2*x*y)/(x^2 + y^2)}, {x, -2, 2}, {y, -2, 2}, 
 PlotStyle -> Thickness[1]]

thick

And remember to watch your units - if you print in millimetres, 1 is a bit small...

For Version 10

The above no longer works in Mathematica version 10. Instead of Plot3D, use ParametricPlot3D:

ParametricPlot3D[{x, y, (2 x y)/(x^2 + y^2)}, {x, -2, 2}, {y, -2, 2},
 PlotStyle -> Thickness[1]]

still thick

$\endgroup$
5
  • $\begingroup$ This may be version 9 and later, not sure... $\endgroup$
    – cormullion
    Commented Nov 24, 2013 at 8:31
  • $\begingroup$ What about AbsoluteThickness? edit: it seems it's not supported. $\endgroup$
    – shrx
    Commented Nov 24, 2013 at 11:54
  • $\begingroup$ @shrx AbsoluteThickness doesn't appear to work for this application... $\endgroup$
    – cormullion
    Commented Nov 24, 2013 at 12:01
  • $\begingroup$ @MichaelE2 :) our answers reflect our contrasting math skills... $\endgroup$
    – cormullion
    Commented Nov 24, 2013 at 12:55
  • $\begingroup$ This seems to be a special-case plot style for Plot3D, ParametricPlot3D and perhaps others, which does just what I tried to do in my answer (expand along the normals), but with proper VertexNormals along the edges. Undocumented (as far as I can see). $\endgroup$
    – Michael E2
    Commented Nov 24, 2013 at 14:39
22
$\begingroup$

In version 10.0.0 the PlotStyle -> Thickness method shown by cormullion does not appear to work. Instead we can use the undocumented Extrusion option:

ContourPlot3D[x y z == 0.05, {x, -1, 1}, {y, -1, 1}, {z, -1, 1}, Extrusion -> 0.1]

enter image description here

$\endgroup$
4
  • 3
    $\begingroup$ Aaaaaaagh. They're supposed to add new features for new releases, not remove ones.. $\endgroup$
    – cormullion
    Commented Jul 16, 2014 at 16:36
  • 1
    $\begingroup$ Which works in ContourPlot3D even though it's Red so unrecognized as an option but doesn't work and is rejected by ListContourPlot3D!!! Echoing Aaaaaaaagh. V. 10.1. $\endgroup$
    – Ymareth
    Commented Apr 3, 2015 at 18:23
  • 1
    $\begingroup$ @Ymareth Seems Extrusion (still undocumented) works now also in ListContourPlot3D since v10.2. See this post $\endgroup$
    – SquareOne
    Commented Oct 29, 2015 at 10:49
  • $\begingroup$ @Ymareth To avoid Red , Method -> {"Extrusion" -> .1} $\endgroup$
    – cvgmt
    Commented Sep 7, 2023 at 8:49
19
$\begingroup$

You can take advantage of the VertexNormals that Plot computes to translate the surface a little to each side. I'm not sure just what is required for good STL output. I put a polygonal side all around the two surfaces. The VertexNormals are wrong for the sides, so I commented them out for the image presented.

The thickness is controlled by the parameter thickness.

With[{plot = Plot3D[{(2*x*y)/(x^2 + y^2)}, {x, -2, 2}, {y, -2, 2}, Mesh -> None]}, 
 With[{n0 = VertexNormals /. Cases[plot, HoldPattern[VertexNormals -> _], Infinity],
       thickness = 0.1}, 
  With[{pts = First @
         Cases[plot, 
               GraphicsComplex[p_, e__] :> Flatten[{p - thickness n0, p + thickness n0}, 1],
               Infinity],
        vn = First @ Cases[plot, HoldPattern[VertexNormals -> v_] :> Join[v, v], Infinity]},
   Graphics3D[
    GraphicsComplex[
     pts,
     {EdgeForm[],
      Cases[plot, Polygon[p_] :> Polygon@Join[p, p + Length[pts]/2], Infinity],
      Cases[plot, 
       Line[p_] :> Polygon[Join[#, Reverse@# + Length[pts]/2] & /@ Partition[p, 2, 1]],
       Infinity]}
     (*, VertexNormals -> vn *)
     ],
    PlotRange -> All,
    Options[plot]
    ]
   ]]]

Graphics

$\endgroup$
2
  • 3
    $\begingroup$ This was a very detailed answer, and I appreciate you taking the time to write it. I chose the other only out of simplicity but I am sure your answer may have future benefits, thanks. $\endgroup$
    – ratman2050
    Commented Nov 24, 2013 at 23:22
  • $\begingroup$ Hey, no problem. The other way is definitely superior based on simplicity. Also, the other answer does what this one does and more. $\endgroup$
    – Michael E2
    Commented Nov 24, 2013 at 23:26
7
$\begingroup$

As of Version 11 there are the PlotThemes "ThickSurface" and "FilledSurface".

Plot3D[{(2*x*y)/(x^2 + y^2)}, {x, -2, 2}, {y, -2, 2}, PlotTheme -> "ThickSurface"]

enter image description here

Plot3D[{(2*x*y)/(x^2 + y^2)}, {x, -2, 2}, {y, -2, 2}, PlotTheme -> "FilledSurface"]

enter image description here

$\endgroup$
2
  • $\begingroup$ Can Mathematica 11 vary the value of "ThickSurface"? If yes how? Could you share a line of code? I have this: PlotTheme -> "ThickSurface" but the thickness is to big. thank you $\endgroup$
    – M. Joe
    Commented Oct 23, 2017 at 10:29
  • 1
    $\begingroup$ @M.Joe I think you'll adapt Simon Wood's answer by using the undocumented option Extrusion. $\endgroup$
    – Greg Hurst
    Commented Oct 23, 2017 at 17:49

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.