0
$\begingroup$

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?

$\endgroup$
1
$\begingroup$

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

| improve this answer | |
$\endgroup$
  • $\begingroup$ Thank you! I'm trying to apply it to mine(with hundreds of Prisms) $\endgroup$ – dodo_nuna_2nd Sep 10 at 2:14
  • $\begingroup$ The prisms in my code are combined with Translate and Rotate functions. It seems RegionUnion is not working in this case... $\endgroup$ – dodo_nuna_2nd Sep 10 at 2:23
  • $\begingroup$ @dodo_nuna_2nd You need to apply RegionUnion to a flattened list of regions. $\endgroup$ – Tim Laska Sep 10 at 3:05
  • $\begingroup$ Thank you! I think I can make it! $\endgroup$ – dodo_nuna_2nd Sep 10 at 5:23
0
$\begingroup$

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...

| improve this answer | |
$\endgroup$
  • $\begingroup$ Same error. \ DiscretizeRegion::regpnd: A non-degenerate region is expected at position 1 of~ . Export::type: Region cannot be exported to the STL format. $\endgroup$ – dodo_nuna_2nd Sep 10 at 0:50
  • $\begingroup$ Thank you! But looks a little bit difficult to my actual code. $\endgroup$ – dodo_nuna_2nd Sep 10 at 5:24

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.