1
$\begingroup$

I have the code of a spherical gyroid written in Mathematica and I am unable to save it in STL format. The image is shown in the figure below and the code is shown below. I need help with a code on how to save it as an STL file.

enter image description here

r = 2 Pi; model = ContourPlot3D[ Sin[x] Cos[y] + Sin[y] Cos[z] + Sin[z] Cos[x] == 0, {x, -r, r}, {y, -r, r}, {z, -r, r}, RegionFunction -> ({x, y, z} \[Function] x^2 + y^2 + z^2 <= r^2), Mesh -> None, PlotTheme -> "ThickSurface", Method -> {"Extrusion" -> .3}] 
$\endgroup$
2
  • $\begingroup$ Export["output.stl", model] doesn't work? $\endgroup$ Commented Nov 25, 2020 at 12:16
  • $\begingroup$ Good evening sir, the code doesn't work, I will be grateful if you give me your own code. I have been stressing about this for two weeks now $\endgroup$ Commented Nov 25, 2020 at 19:13

3 Answers 3

2
$\begingroup$

First remove the Box and Axes

r=2 Pi; model = ContourPlot3D[Sin[x] Cos[y] + Sin[y] Cos[z] + Sin[z] Cos[x] == 0, {x, -r,r}, {y, -r, r}, {z, -r, r},RegionFunction -> ({x, y, z} \[Function] x^2 + y^2 + z^2 <= r^2),Mesh -> None,PlotTheme -> "ThickSurface",Method -> {"Extrusion" -> .3} , Axes -> False, Boxed -> False] 

enter image description here

Now you might use the answer (thanks @Henrik Schumacher) of your own question from march2020 how to save a file in STL format

Export[…,DiscretizeGraphics[model]] 
$\endgroup$
9
  • $\begingroup$ thank you for the answer Sir, but here is the complete code, once I run it gives me an error...r = 2 Pi; model = ContourPlot3D[ Sin[x] Cos[y] + Sin[y] Cos[z] + Sin[z] Cos[x] == 0, {x, -r, r}, {y, -r, r}, {z, -r, r}, RegionFunction -> ({x, y, z} [Function] x^2 + y^2 + z^2 <= r^2), Mesh -> None, PlotTheme -> "ThickSurface", Method -> {"Extrusion" -> .3}, Axes -> False, Boxed -> False, Export["a.stl", DiscretizeGraphics[model]]] $\endgroup$ Commented Nov 25, 2020 at 19:06
  • $\begingroup$ The code runs on v12 Windows 10. What errors occur? $\endgroup$ Commented Nov 25, 2020 at 19:08
  • $\begingroup$ I will be grateful if you send me your own code Sir, I have that windows version $\endgroup$ Commented Nov 25, 2020 at 19:10
  • $\begingroup$ Copy the three lines of code from my answer, quit your kernel and run the code. That's all. That's all I have. $\endgroup$ Commented Nov 25, 2020 at 19:15
  • 1
    $\begingroup$ In 12.1.1,we must set RegionBoundaryStyle -> None to remove the extra sphere, it maybe a bug. Perhaps this settings cause the kernel crash when we using DiscretizeGraphics $\endgroup$ Commented Nov 26, 2020 at 9:05
2
$\begingroup$

Another way maybe use RegionPlot3D. Here we calculate the normal of surface and then perturbate the surface along the normal to create a thick surface.

r = 2 Pi; f = Sin[x] Cos[y] + Sin[y] Cos[z] + Sin[z] Cos[x]; normal = Grad[f, {x, y, z}]; norm = normal^2 // Total // Evaluate; model = RegionPlot3D[ x^2 + y^2 + z^2 <= r^2 && f^2 <= 0.01 norm, {x, -r, r}, {y, -r, r}, {z, -r, r}, Mesh -> None, Boxed -> False, Axes -> False, PlotPoints -> 100] Export["output.stl", model] Import["output.stl"] 

enter image description here

$\endgroup$
1
  • $\begingroup$ r = 2 Pi; model = ContourPlot3D[ Sin[x] Cos[y] + Sin[y] Cos[z] + Sin[z] Cos[x] == 0, {x, y, z} \[Element] Ball[{0, 0, 0}, r], Method -> {"Extrusion" -> .3}, RegionBoundaryStyle -> None, Mesh -> None] $\endgroup$ Commented May 25, 2024 at 12:13
0
$\begingroup$

I tried a number of suggestions from different posts to make surface thickness work for 3D printing, but nothing worked for me until I used "Export[…,DiscretizeGraphics[model]]" as shown on this thread, and then it worked like a charm.

$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.