Message Boards Message Boards

GROUPS:

Generate a STL file including a cylinder, a ball and a prism?

Posted 6 months ago
652 Views
|
7 Replies
|
6 Total Likes
|

I want to generate a STL file including a cylinder, a ball and a prism using

c = Cylinder[{{0, 0, 0}, {0, 0, 1}}, 1];

    b = Ball[{0, 0, 1}, 1];
    p = Prism[{{1, 0, 1}, {0, 0, 0}, {2, 0, 0}, {1, 2, 1}, {0, 2, 0}, {2, 
         2, 0}}];
    t = Graphics3D[{c, b, p}];
    Export["f:\\3.stl", t]”.

But I only find the cylinder when using "Import["f:\3.stl"] Where are the other two going? Thanks:)

7 Replies

Execute code:

 b = Ball[{0, 0, 1}, 1];
 p = Prism[{{1, 0, 1}, {0, 0, 0}, {2, 0, 0}, {1, 2, 1}, {0, 2, 0}, {2, 2, 0}}];
 t = Graphics3D[{b, p}]
 Export["f:\\3.stl", t]

And what Yours conclusions ?

Posted 6 months ago

Thank you for your response! The conclusion is very funny.

When I excute

b = Ball[{0, 0, 1}, 1];
p = Prism[{{1, 0, 1}, {0, 0, 0}, {2, 0, 0}, {1, 2, 1}, {0, 2, 0}, {2, 2, 0}}];
t = Graphics3D[{b, p}]
Export["f:\\3.stl", t]

The system tells me "The function DiscretizeGraphics is not implemented for it" and "Graphics3D cannot be exported to the STL format".

When I excute

p = Prism[{{1, 0, 1}, {0, 0, 0}, {2, 0, 0}, {1, 2, 1}, {0, 2, 0}, {2, 2, 0}}];
t = Graphics3D[{p}]
Export["f:\\3.stl", t]

I can successfully ex- and import the prism.

When I excute

b = Ball[{0, 0, 1}, 1];
t = Graphics3D[{b}]
Export["f:\\3.stl", t]

I can successfully ex- and import the ball.

When I excute

c = Cylinder[{{0, 0, 0}, {0, 0, 1}}, 1];
b = Ball[{0, 0, 1}, 1];
t = Graphics3D[{c, b}];
Export["f:\\3.stl", t]

I can only get the cylinder.

When I excute

c = Cylinder[{{0, 0, 0}, {0, 0, 1}}, 1];
p = Prism[{{1, 0, 1}, {0, 0, 0}, {2, 0, 0}, {1, 2, 1}, {0, 2, 0}, {2, 
     2, 0}}];
t = Graphics3D[{c, p}];
Export["f:\\3.stl", t]

Again, I can only get the cylinder.

I guess if you try your system, you will see the same thing, right? My mathematica version is 10.2.

Probably,the error occurs because the figures 3D penetrate each other.Yes the same error on my MMA 11.3 version.

Workaround is using RegionUnion function:

c = Cylinder[{{0, 0, 0}, {0, 0, 1}}, 1]; b = Ball[{0, 0, 1}, 1];
t = RegionUnion[c, b];
Export["f:\3.stl", t]

Visualize it:

 RegionUnion[c, b]//Region

enter image description here

Posted 6 months ago

Yes, you find an effective way to combine geometries. But there's still problem. When I run this:

rg = RegionUnion[Cylinder[{{0.7, 0, 1.4}, {0.1, 0, 2.1}}, .1], 
  Ball[{0.1, 0, 2.1}, .1], 
  Cylinder[{{0.1, 0, 2.1}, {-0.4, 0.6, 1.6}}, .1]];
Export["f:\3.stl", rg]

I want to use a ball connecting two cylinders, but the result is very coarse. Is there any way to improve the resolution? :)

Maybe is a limtation of file format or something else.

With dxf file format works fine:

  t = Graphics3D[{Cylinder[{{0.7, 0, 1.4}, {0.1, 0, 2.1}}, .1], 
  Ball[{0.1, 0, 2.1}, .1], 
  Cylinder[{{0.1, 0, 2.1}, {-0.4, 0.6, 1.6}}, .1]}]

  Export["test.dxf", t]
  Import["test.dxf"]

enter image description here

Another workaround:

   a = Cylinder[{{0.7, 0, 1.4}, {0.1, 0, 2.1}}, .1];
   b = Ball[{0.1, 0, 2.1}, .1];
   c = Cylinder[{{0.1, 0, 2.1}, {-0.4, 0.6, 1.6}}, .1];

   a1 = BoundaryDiscretizeGraphics[a, 
      MaxCellMeasure -> {"Length" -> 0.05}];(* Discretize with a maximum edge length of 0.05*)
   b1 = BoundaryDiscretizeGraphics[b, 
      MaxCellMeasure -> {"Length" -> 0.05}];
   c1 = BoundaryDiscretizeGraphics[c, 
      MaxCellMeasure -> {"Length" -> 0.05}];

    reg = RegionUnion[a1, b1, c1]
    Export["test.stl", reg]
    Import["test.stl"]

enter image description here

Posted 6 months ago

For the dxf case, my MMA still misses the ball:(

For the discretize case, it said: "DiscretizeRegion was unable to discretize the region RegionUnion" and "RegionUnion cannot be exported to the STL format".

Is this because your version is higher than mine? My aim is 3d printing, so I need stl format. Do you feel it's a bug of MMA? There is no reason treating cylinder and ball differently!

Possible Solution:

  • Mathematica Guru(Jedi) will come here and solve your attempt.
  • Put your question here maybe they will answer your questions there.
  • You must upgrade to version 11.3
  • Use other 3d software.Blender 3D is free and can export to stl files.
  • or something else..

Regards,MI

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract