TransWikia.com

Exporting several prisms (or Polyhedrons) to stl (with filled inner space)

Mathematica Asked by dodo_nuna_2nd on December 24, 2020

I want to export hundreds of prisms to stl. And for this stl file to be 3D printable, its inner space must be filled.

I’ve tried two approaches to solve this problem.
(just two prisms for a brief explanation)

  1. The first one is using "Prisms" (https://reference.wolfram.com/language/ref/Prism.html)
    enter image description here

As I ultimately want to make several prisms, I can make them with Graphics3D but cannot export them to stl at once.

twoprisms = Graphics3D[{Prism[{{1, 0, 1}, {0, 0, 0}, {2, 0, 0}, {1, 2, 1}, {0, 2, 0}, {2, 2, 0}}], Prism[{{1, 2, 1}, {0, 2, 0}, {2, 2, 0}, {1, 4, 1}, {0, 4, 0}, {2, 4, 0}}]}]
Export["twoprisms.stl", twoprisms]
  1. The next approach is thickening polygons to prisms (Thick polygons in Graphics3D)
    enter image description here

(This code is from @jVincent, not me)

normal[a_, b_, c_] := Normalize@Cross[a - b, c - b]
normal[a___] := Mean[normal @@@ Partition[{a}, 3, 1, 1]]
sides[bottom_, top_] := Polygon[Reverse@Join[#1, Reverse@#2]] & @@@ ({bottom, top} // Transpose // Partition[#, 2, 1, 1] &)
thicken[val_, t_: 0.1] := val /. Polygon[bottom_, ___] :> With[{top = (# + t normal @@ bottom) & /@ bottom}, {Polygon[Reverse@bottom], sides[bottom, top], Polygon[top]}]
initial = Graphics3D[{Polygon[{{1, 1, 0}, {1, 2, 0}, {2, 1, 0}}], Polygon[{{0, 0, 0}, {1, 0, 0}, {0, 1, 0}}]}];
inital2 = thicken[initial, 0.3]
Export["inital.stl", initial]

This one can be exported to stl file. But it’s hollow. (not 3D printable)

How can I make several filled prisms to stl file?

2 Answers

Here is another way try using ToElementMesh:

Needs["NDSolve`FEM`"]
twoprisms2 = 
  RegionUnion@{Prism[{{1, 0, 1}, {0, 0, 0}, {2, 0, 0}, {1, 2, 1}, {0, 
       2, 0}, {2, 2, 0}}], 
    Prism[{{1, 2, 1}, {0, 2, 0}, {2, 2, 0}, {1, 4, 1}, {0, 4, 0}, {2, 
       4, 0}}]};
mr = MeshRegion@
   ToElementMesh[twoprisms2, MaxCellMeasure -> Infinity, 
    "MeshOrder" -> 1];
Export["testprism.stl", mr];

One possible advantage to the ToElementMesh approach is that the model should be watertight since it is used for FEM modeling.

Extension to multiple prisms

To extend to the two prism case, remove the Graphics3D from initial so that it may be treated as a region. Then, use the following code:

initial = {Polygon[{{1, 1, 0}, {1, 2, 0}, {2, 1, 0}}], 
   Polygon[{{0, 0, 0}, {1, 0, 0}, {0, 1, 0}}]};
initial2 = RegionUnion @@ Flatten[thicken[initial, 0.3]];
mr = MeshRegion@
   ToElementMesh[initial2, MaxCellMeasure -> Infinity, 
    "MeshOrder" -> 1];
Export["twoprism.stl", mr];
Import["twoprism.stl"]

enter image description here

Correct answer by Tim Laska on December 24, 2020

Update

Perhaps we can direct use BoundaryMeshRegion

Clear["`*"];
bmr1 = BoundaryMeshRegion[{{0, 0}, {1, 0}, {1, 1}, {0, 1}, {2, 1}, {2,
      2}, {1, 2}}, Line[{{1, 2, 4, 1}, {3, 5, 6, 3}}]];
bmr2 = BoundaryMeshRegion[{{0}, {1}}, Point[{{1}, {2}}]];
RegionProduct[bmr1, bmr2];
Export["two.stl", %]

enter image description here

Original

twoprisms = 
 Region /@ {Prism[{{1, 0, 1}, {0, 0, 0}, {2, 0, 0}, {1, 2, 1}, {0, 2, 
       0}, {2, 2, 0}}], 
    Prism[{{1, 2, 1}, {0, 2, 0}, {2, 2, 0}, {1, 4, 1}, {0, 4, 0}, {2, 
       4, 0}}]} // RegionUnion

 Export["twoprisms.stl", twoprisms]

first Update

Clear["`*"];
data1 = {{1, 0, 1}, {0, 0, 0}, {2, 0, 0}, {1, 2, 1}, {0, 2, 0}, {2, 2,
     0}};
data2 = {{1, 2, 1}, {0, 2, 0}, {2, 2, 0}, {1, 4, 1}, {0, 4, 0}, {2, 4,
     0}};
sets = {Partition[data1, 3], Partition[data2, 3]}
Flatten[Complement[Union @@ sets, Intersection @@ sets], 1] // 
  Prism // Region
Export["newtwoprism.stl", %]
Import["newtwoprism.stl"]

enter image description here

Need to be updated...

Answered by cvgmt on December 24, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP