4
$\begingroup$

For vizualization purposes in a beamer presentation I would like to project a 3D MeshRegion like ConvexHullMesh[RandomReal[{-1, 1}, {50, 3}]] onto a 2D plane. How can this be achieved?

$\endgroup$

1 Answer 1

5
$\begingroup$

You can simply feed the 3D BoundaryMeshRegion into the 2D RegionPlot:

rr = ConvexHullMesh[RandomReal[{-1, 1}, {50, 3}]]
RegionPlot[rr]

To choose a different projection, apply a rotation, e.g. like this:

RegionPlot[Rotate[rr, {{1, 1, 1}, {1, 0, 1}}]]

Edit:

Here is how I checked that this indeed does a projection onto the $xy$ plane rather than an intersection with some plane (which presumably would be at $z=0$):

First I define a polyhedron that contains a triangle parallel to the $xy$ plane but shifted so it doesn't intersect this plane.

region = 
 BoundaryMeshRegion[{{0, 0, 1}, {2, 0, 1}, {0, 1/2, 1}, {0, 0, 2}}, 
  Polygon[{{1, 2, 3}, {1, 2, 4}, {2, 3, 4}, {1, 3, 4}}]]

The base is a right triangle with side lengths 2 and 1/2 adjacent to the right angle. Let's see if we can identify this in the projection:

RegionPlot[region, AspectRatio -> Automatic]

projection

This is what I'd expect as the projection.

Edit 2:

A more pedestrian way of getting a projection (good as a sanity check) would be this:

Graphics[Inset[
  RegionPlot3D[rr, BoxRatios -> {1, 1, 0.0001}, 
   PlotStyle -> FaceForm[Blue], Lighting -> {"Ambient", White}, 
   ViewPoint -> Top], Automatic, Automatic, Scaled[1]]]

This outline agrees with the projection obtained from RegionPlot above. The way I did this is to squish the three-dimensional output of RegionPlot3D by reducing the side length of the z dimension to nearly zero in BoxRatios. To create a 2D Graphics out of this squished 3D object, I use an Inset.

$\endgroup$
2
  • $\begingroup$ Does this really give an (orthogonal) projection? After Reading about RegionPlot, I actually don't understand how this works (e.g., on which plane does it project?). Could it be, that this instead gives the intersection of the convex hull with some plane? $\endgroup$ Jul 15, 2018 at 22:49
  • $\begingroup$ As far as I can tell, it does provide the projection onto the $xy$ plane by dropping the $z$ coordinate. I'll edit the answer to show how I've tested that... $\endgroup$
    – Jens
    Jul 15, 2018 at 23:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.