6
$\begingroup$

I want to 3d print this solid (Riemann sums):

f[x_, y_] := 3/(x^2 + y^2 + 1)
model = GraphicsRow[{With[{h = .5}, 
Graphics3D[{(Cuboid @@ # &) /@ 
   Flatten[Table[{{x, y, 0}, {x + h, y + h, f[x + h/2, y + h/2]}},
     {x, -2, 2 - h, h}, {y, -2, 2 - h, h}], 1]}, Axes -> True]]}]

Export["riemann.STL", %]

I get the error message "Export::type: Graphics cannot be exported to the STL format."

How can I change my code so that I can print this solid?

riemann sum

$\endgroup$
1
  • 1
    $\begingroup$ Remove the GraphicsRow and List wrappers. The Export examples in the "STL" documentation are not wrapped in GraphicsRow. $\endgroup$
    – Edmund
    Mar 23, 2022 at 22:33

3 Answers 3

4
$\begingroup$
Clear[model];
f[x_, y_] = 3/(x^2 + y^2 + 1);
model = With[{h = .5}, 
  RegionUnion[(Cuboid @@ # &) /@ 
     Flatten[Table[{{x, y, 0}, {x + h, y + h, 
         f[x + h/2, y + h/2]}}, {x, -2, 2 - h, h}, {y, -2, 2 - h, h}],
       1], Axes -> True]]
Export["riemann.stl", model]

enter image description here

$\endgroup$
1
  • $\begingroup$ BTW,I don't know how to use DiscretePlot3D to plot such region.DiscretePlot3D[f[x, y], {x, -2, 2, .5}, {y, -2, 2, .5}, ExtentSize -> Full, AspectRatio -> 1] does not plot the same region. $\endgroup$
    – cvgmt
    Mar 24, 2022 at 1:56
4
$\begingroup$

You can also avoid the region stuff (RegionUnion and Cuboid) by using DiscretizeGraphics. You can generate an appropriate graphic with ListPlot3D.

model =
  With[
    {h = .5},
    ListPlot3D[Table[f[x, y], {x, -2 + h, 2, h}, {y, -2 + h, 2, h}], 
      InterpolationOrder -> 0, Filling -> Axis]]

My adjustments for making the Table might be wrong in the details, but hopefully you can see how this would work with ListPlot3D. Now,

printableModel = DiscretizeGraphics[model]

And finally,

Printout3D[printableModel, "riemann.stl"]

Although, in this particular case, it appears that you can skip the DiscretizeGraphics step. The following also seems to work:

Printout3D[model, "riemann.stl"]

Using Printout3D is also somewhat nicer that Export, because it'll do some model verification (although in my experience it can sometimes still produce a model that some slicers can't handle).

$\endgroup$
2
$\begingroup$

This comes only as a supplement to solution suggested by cvgmt plus the comment underneath it.



We have:

Quit[]

$Version

"13.0.0 for Mac OS X ARM (64-bit) (December 3, 2021)"

f[x_, y_] := 3/(x^2 + y^2 + 1)

With[{h = 0.5}, 
 DiscretePlot3D[f[x, y], {x, -2, 2, h}, {y, -2, 2, h}, 
  ExtentSize -> Full, AspectRatio -> 1, 
  ColorFunction -> "BlueGreenYellow"]]

dplt3d


Edit: the part of code which I missed as I copied and pasted here.


model = DiscretePlot3D[f[x, y], {x, -2, 2}, {y, -2, 2}, 
  ExtentSize -> Full, AspectRatio -> 1, 
  ColorFunction -> "BlueGreenYellow"]

Export["riemann.stl", model]

and then we Import what we did

Import["riemann.stl"]

the output of which is

import

$\endgroup$
2
  • 1
    $\begingroup$ Thank you. This seems to work. $\endgroup$
    – epsilon
    Mar 26, 2022 at 3:10
  • $\begingroup$ @epsilon glad I helped! $\endgroup$
    – bmf
    Mar 26, 2022 at 3:11

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