# Smoothing the Region？

There is a 2D Pi

I successed transformed it to 3D.

extrudeImage[image_] :=
Block[{res, img},
img = DeleteSmallComponents[Binarize[image, 0.9], 500];
res = ImageMesh[img];
RegionProduct[res, Line[{{0.}, {10.}}]]]

img = DeleteBorderComponents@
ImageResize[Import["https://i.stack.imgur.com/AM0gC.png"], 100];
r = Region[extrudeImage@img, Axes -> True,
AxesLabel -> {"X", "Y", "Z"}];
r = TransformedRegion[r, TranslationTransform[-RegionCentroid@r]]


I tried to rotate it to create a more 3D Pi, but the surface seemed to be too rough, MMA can't export STL format.

RegionUnion@
Table[TransformedRegion[r, RotationTransform[i, {0, 1, 0}]], {i, 0,
Pi/3, Pi/10}]
Export["test.stl", %]


How to make the surface smooth so that 3D printer can be used?

You need DiscretizeRegion and RepairMesh:

r = Region[extrudeImage@img, Axes -> True, AxesLabel -> {"X", "Y", "Z"}];
r2 = TransformedRegion[r, TranslationTransform[-RegionCentroid@r]];

r3 = DiscretizeRegion@r2 // RepairMesh

rfinal = RegionUnion@
Table[TransformedRegion[r3, RotationTransform[i, {0, 1, 0}]],
{i, 0, Pi/3, Pi/30}] // RepairMesh; // AbsoluteTiming
(* {117.008, Null} *)

Export["testfinal.stl", rfinal]


## Update

DiscretizeRegion turns out to be unnecessary, because the output of extrudeImage is already a MeshRegion, so we just need:

r = extrudeImage@img

r2 = TransformedRegion[r, TranslationTransform[-RegionCentroid@r]]

r3 =
RegionUnion@
Table[TransformedRegion[r2 // RepairMesh, RotationTransform[i, {0, 1, 0}]], {i, 0,
Pi/3, Pi/75}]; // AbsoluteTiming
(* {0.296961, Null} *)

Export["test3.stl", r3]


Notice the last RepairMesh has also been taken away, because r3 == RepairMesh@r3 turns out to be True.

• Thank you! May be the quanlity can be improved by rnew = ImageMesh@RegionImage[rfinal];, but too slow. Sep 25, 2020 at 14:00
• @partida I guess something like {i, 0, Pi/3, Pi/75} should improve the quality, but repairing this is again slow. (The last RepairMesh might not be necessary though. You may check if the model created without the last RepairMesh is defectless in the preview of 3D printer. ) Sep 25, 2020 at 14:55
• However RepairMesh effects the dimension of Region! try RegionDimension@RepairMesh@DiscretizeRegion@r2 and RegionDimension@DiscretizeRegion@r2 Sep 26, 2020 at 9:48
• @partida That should not be a problem. The RegionDimension of disgra here is also 2, but I still manage to print it. Sep 26, 2020 at 10:55
• However the rfinal can't be processed in 3D again. try RegionIntersection[rfinal, Region@Cylinder[{{0, -30, 0}, {0, 30, 0}}, 20]] Sep 27, 2020 at 0:02