0
$\begingroup$

I am attempting to model a cross section problem from Calculus II using the general slicing method. Below is the working code to generate the "slices" of the defined problem; however, I would like to export this to an STL file to 3D print it. I have created a working code for another problem that has squares as cross sections. I've attached the working code that will export the STL code as wanted.

n=10
a=-2
b=2
dx=(b-a)/n
f[x_]:=(4-x^2)^0.5
listOfCuboids=Table[Cuboid[{x+dx,0,0},{x,f[x],f[x]}],{x,Subdivide[a,b,n]} ]
solid=Graphics3D[listOfCuboids]
Printout3D[solid,"cuboids.stl"]

For the original problem that I'm trying to model, the code is as such.

n=10
a2=0
b2=4
dy=(b2-a2)/n
g[y_]:=y^(0.5)
listOfPrisms=Table[Prism[{{0,y,g[3*y]}, {-g[y],y,0}, {g[y],y,0}, {0,y+dy,g[3*y]}, {-g[y],y+dy,0}, {g[y],y+dy,0}}],{y,Subdivide[a2,b2,n]}]
solid2=Graphics3D[listOfPrisms]
Printout3D[solid2,"prisms.stl"]

However, this code does not export to an STL file and the report of the output says it could not discretize or export the file. Any help would be appreciated.

Thanks to the previous comments for helping me to improve the code.

Final Update Here is an image of the 3D print! Thanks again all who helped. enter image description here

$\endgroup$
  • $\begingroup$ You never defined solids2. You only defined listOfPrisms. Even then, your list is not a well-defined Region; you may have some luck with RegionUnion. As an aside, please note that your AppendTo code is quite inefficient; try instead: listOfPrisms = Table[ Prism[{{0, y, g[3 y]}, {-g[y], y, 0}, {g[y], y, 0}, {0, y + dy, g[3 y]}, {-g[y], y + dy, 0}, {g[y], y + dy, 0}}], {y, Subdivide[0, 4, 10]} ], which will achieve the same, but faster. $\endgroup$ – MarcoB Feb 15 at 23:20
  • $\begingroup$ Does Printout3D[ RegionUnion @@ BoundaryDiscretizeGraphics /@ First[solid2], "cuboids.stl"] work for you? If so I'll make this an answer. $\endgroup$ – Chip Hurst Feb 16 at 1:29
  • $\begingroup$ That does not work. It says that "The cell Prism[{1, 2, 5, 4}] is degenerate. $\endgroup$ – Ethan Smith Feb 16 at 1:34
  • 1
    $\begingroup$ It also says BoundaryDiscretizeGraphics: The graphics primative Prism[{etc.}] is not valid. Among a few other erros. $\endgroup$ – Ethan Smith Feb 16 at 1:34
  • 1
    $\begingroup$ We must be running different versions. The first prism is degenerate. Does RegionUnion @@ BoundaryDiscretizeGraphics /@ Rest[First[solid2]] work? $\endgroup$ – Chip Hurst Feb 16 at 2:39
2
$\begingroup$

We can manually drop the degenerate case:

solid2 = RegionUnion @@ BoundaryDiscretizeGraphics /@ Rest[listOfPrisms]

Printout3D[solid2, "prisms.stl"]["Status"]
"Successful"
$\endgroup$
  • $\begingroup$ Thanks again. 3D printing them now. $\endgroup$ – Ethan Smith Feb 16 at 17:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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