Turning a 3D graphics object into a region

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

Executing DiscretizeGraphics[gsofa] (where gsofa is the graphics object) produces this:

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?

Cf. the MathOverflow question where this arose.

• Is the "complex shape" a GraphicsComplex[] object (easy), or a bunch of Polygon[]s (a bit harder)? Aug 14 '16 at 15:06
• @J.M.: A bunch of polygons. But I guess it wouldn't be too hard to convert to a GraphicsComplex if that would help. Aug 14 '16 at 15:07
• 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. Aug 14 '16 at 15:18
• @J.M. I have all vertex coordinates. I will explore MeshRegion (with which I was not familiar). Thanks! Aug 14 '16 at 15:21
• 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 Aug 15 '16 at 16:36

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


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
]


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


You can measure this region

RegionMeasure[cylindersMinus]

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


It appears to discretize fine

DiscretizeRegion[cylindersMinus]