8
$\begingroup$

The Graphics3D format has more styling options than mesh based graphics, so I was wondering if there was a way to convert mesh based objects such as region intersections and unions back into the Graphics3D format.

$\endgroup$
  • $\begingroup$ Could you give us an example of such a mesh? $\endgroup$ – MarcoB Jun 11 '18 at 22:00
  • 4
    $\begingroup$ Show[meshregion]? $\endgroup$ – Michael E2 Jun 12 '18 at 0:01
  • $\begingroup$ Welcome to Mathematica.SE! I suggest that: 1) You take the introductory Tour now! 2) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! 3) As you receive help, try to give it too, by answering questions in your area of expertise. $\endgroup$ – halirutan Jun 12 '18 at 1:29
7
$\begingroup$

Michaels comment is completely correct. By using Show, the region gets transformed back into a graphics, although it doesn't look like that. There is one major difference to my answer: While I'm extracting the polygons and the final Graphics3D will only contain these primitives, using Show wraps the polygons into an Annotation[poly, "Geometry"].

This is just for your information. Here is how you can extract the polygons and create a new Graphics3D:

{cube, cone} = DiscretizeRegion /@ {Cuboid[], Cone[]};
reg = RegionIntersection[cube, cone]

Mathematica graphics

MeshPrimitives[reg, 2] // Graphics3D

Mathematica graphics

$\endgroup$
  • $\begingroup$ thank you, now I no longer need to worry about using my own functions for rotation and intersection $\endgroup$ – Brian Luvalle Jun 12 '18 at 1:27
5
$\begingroup$

It might be more efficient to use a GraphicsComplex for regions with many polygons

Graphics3D[{
  GraphicsComplex[MeshCoordinates[reg],MeshCells[reg, 2, "Multicells" -> True]]
  }]

Whenever reg is a MeshRegion, it is also a good idea to first convert it to a BoundaryMeshRegion with BoundaryMesh[reg]. Otherwise, also all interior (and thus invisible) polygons will be written into the GraphicsComplex (and have to be processed by the z-buffer of the GPU during rendering).

$\endgroup$
5
$\begingroup$

In Mathematica 12, MeshRegion and BoundaryMeshRegion objects act as graphics primitives in Graphics3D. So:

{cube, cone} = DiscretizeRegion /@ {Cuboid[], Cone[]};
reg = RegionIntersection[cube, cone];

Graphics3D[{LightGreen, EdgeForm[None], reg}]

enter image description here

$\endgroup$

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.