There is a 2D Pi

enter image description here

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

enter image description here

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.

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

enter image description here

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]


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 = 
    Table[TransformedRegion[r2 // RepairMesh, RotationTransform[i, {0, 1, 0}]], {i, 0, 
      Pi/3, Pi/75}]; // AbsoluteTiming
(* {0.296961, Null} *)

Export["test3.stl", r3]

enter image description here

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

  • $\begingroup$ Thank you! May be the quanlity can be improved by rnew = ImageMesh@RegionImage[rfinal];, but too slow. $\endgroup$ – partida Sep 25 '20 at 14:00
  • $\begingroup$ @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. ) $\endgroup$ – xzczd Sep 25 '20 at 14:55
  • $\begingroup$ However RepairMesh effects the dimension of Region! try RegionDimension@RepairMesh@DiscretizeRegion@r2 and RegionDimension@DiscretizeRegion@r2 $\endgroup$ – partida Sep 26 '20 at 9:48
  • 1
    $\begingroup$ @partida That should not be a problem. The RegionDimension of disgra here is also 2, but I still manage to print it. $\endgroup$ – xzczd Sep 26 '20 at 10:55
  • $\begingroup$ However the rfinal can't be processed in 3D again. try RegionIntersection[rfinal, Region@Cylinder[{{0, -30, 0}, {0, 30, 0}}, 20]] $\endgroup$ – partida Sep 27 '20 at 0:02

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.