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)
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]
(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?
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.
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"]
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", %]
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"]
Need to be updated...
Answered by cvgmt on December 24, 2020
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP