8
$\begingroup$

I have a somewhat complex 3D shape composed of several polygons:


          Sofa75
Executing DiscretizeGraphics[gsofa] (where gsofa is the graphics object) produces this:
          SofaDisc
I wanted to convert the graphics object to a region so that I could use derived region functions, but it is clear the discretized region does not correspond to the shape. Must I partition the U-shaped faces into convex faces?

Answered by @JackLaVigne:


          SofaRegion
Cf. the MathOverflow question where this arose.

$\endgroup$
7
  • $\begingroup$ Is the "complex shape" a GraphicsComplex[] object (easy), or a bunch of Polygon[]s (a bit harder)? $\endgroup$ Aug 14 '16 at 15:06
  • $\begingroup$ @J.M.: A bunch of polygons. But I guess it wouldn't be too hard to convert to a GraphicsComplex if that would help. $\endgroup$ Aug 14 '16 at 15:07
  • $\begingroup$ Now that I think about it: a generalized cylinder like your example can be easily generated as a (Boundary)MeshRegion[] ab initio, long as you have coordinates for the top and bottom; a more complicated object like the Stanford bunny would be of course much harder. $\endgroup$ Aug 14 '16 at 15:18
  • $\begingroup$ @J.M. I have all vertex coordinates. I will explore MeshRegion (with which I was not familiar). Thanks! $\endgroup$ Aug 14 '16 at 15:21
  • $\begingroup$ can you do something like this instead? RegionUnion[ RegionDifference[Cuboid[{-1, 0, 0}, {1, 1, 1}], Cylinder[{{0, 0, 0}, {0, 1, 0}}, 1/2]], RegionIntersection[Cuboid[{-2, 0, 0}, {-1, 1, 1}], Cylinder[{{-1, 0, 0}, {-1, 1, 0}}, 1]], RegionIntersection[Cuboid[{1, 0, 0}, {2, 1, 1}], Cylinder[{{1, 0, 0}, {1, 1, 0}}, 1]]] // DiscretizeRegion $\endgroup$ Aug 15 '16 at 16:36
5
$\begingroup$

I don't know how helpful this is because I am going by the figure you have for your shape.

That looks to me like two cylinders pointing in the y direction with a cuboid chopping off the top quarter and a second cuboid chopping off the bottom half. Below is a figure of the two cylinders.

Graphics3D[
 {
  {
   Opacity[0.5],
   Cylinder[{{0, 1/4, 0}, {0, 3/4, 0}}, 1],
   Opacity[1],
   Cylinder[{{0, 1/4, 0}, {0, 3/4, 0}}, 1/4]
   }
  },
 Axes -> True,
 AxesLabel -> {"x", "y", "z"},
 BoxRatios -> {1, 1, 1},
 PlotRange -> {{-1, 1}, {0, 1}, {-1, 1}},
 PlotRangePadding -> Scaled[0.05]
 ]

Mathematica graphics

Now create the cylinders as a region difference and remove the top quarter

cylinders = RegionDifference[
  Cylinder[{{0, 1/4, 0}, {0, 3/4, 0}}, 1],
  Cylinder[{{0, 1/4, 0}, {0, 3/4, 0}}, 1/4]
  ]

cylindersMinusTop = RegionDifference[cylinders, Cuboid[{-1, -1, 1/2}, {1, 1, 1}]]

RegionPlot3D[
 cylindersMinusTop,
 Axes -> True,
 AxesLabel -> {"x", "y", "z"},
 BoxRatios -> {1, 1, 1},
 PlotRange -> {{-1, 1}, {0, 1}, {-1, 1}},
 PlotStyle -> Directive[Cyan, Opacity[0.5]],
 PlotPoints -> 100
 ]

Mathematica graphics

Next remove the bottom half

cylindersMinus = RegionDifference[cylindersMinusTop, Cuboid[{-1, -1, -1}, {1, 1, 0}]]

RegionPlot3D[
 cylindersMinus,
 Axes -> True,
 AxesLabel -> {"x", "y", "z"},
 BoxRatios -> {1, 1, 1},
 PlotRange -> {{-1, 1}, {0, 1}, {-1, 1}},
 PlotStyle -> Directive[Cyan, Opacity[0.5]],
 PlotPoints -> 100,
 ImageSize -> 350,
 ViewPoint -> {1.3, -2.4, 2.}
 ]

Mathematica graphics

You can measure this region

RegionMeasure[cylindersMinus]

(* 1/192 (24 Sqrt[3] + 13 π) *)

It appears to discretize fine

DiscretizeRegion[cylindersMinus]

Mathematica graphics

$\endgroup$
1
  • $\begingroup$ Very nice, Jack! Let me think about this... $\endgroup$ Aug 15 '16 at 21:31

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.