# Surface Plot 3D of a strongly concave shape

I have a list of {x,y,z} points that all lie on the surface of an object (model output from COMSOL). I would like to generate a graphics object that reproduces the surface. Ideally, I would like something like a list of polygon indices so that it can be easily colored to match the model output. Because the object contains strong concave regions (right angles) none of the solutions here, here, here, or here seem to work for me.

As an example of the kind of shape I'm trying to draw, consider these points which form a cuboid with a cylindrical piece connected on one side:

Join[Flatten[Table[{i, j, k}, {i, -1, 1, .1}, {j, -2, 2, .1}, {k, {-.5, .5}}], 2],
Flatten[Table[{i, j, k}, {i, {-1, 1}}, {j, -2, 2, .1}, {k, -.5, .5, .1}], 2],
Flatten[Table[{i, j, k}, {i, -1, 1, .1}, {j, {-2, 2}}, {k, -.5, .5, .1}], 2],
Flatten[Table[{.25 Cos[t], .25 Sin[t], k}, {t, 0, (n - 1) 2 \[Pi]/n,
2 \[Pi]/n}, {k, .5, .8, .1}], 1], Flatten[Table[{k Cos[t], k Sin[t], .8},
{t, 0, (n - 1) 2 \[Pi]/n, 2 \[Pi]/n}, {k, 0, .2, .1}], 1]]


To me this seems like such a simple geometry that it is very frustrating that something like ListSurfacePlot3D completely fails to reproduce it. If only my COMSOL model were of a rabbit...

• I should mention that any tricks that depend on exploiting the symmetry here won't help me, since my real object consists of two pieces like this joined at right angles to each other. – djphd Mar 22 '15 at 23:01
• 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. – bbgodfrey Mar 22 '15 at 23:07
• Have you seen this?:reference.wolfram.com/mathematica/TetGenLink/tutorial/… – Dr. belisarius Mar 24 '15 at 4:37
• I've done my best to approach it with TetGenLink, but it seems I have to either accept some default algorithms (eg, Delauny) or hard code it myself, which is exactly what I was hoping to avoid. I'm looking for some more robust algorithm that can take my points and figure out, based on how close they are, which ones to connect. The constraint that should make this possible, in my opinion, is that I already know these are the points on the surface. – djphd Mar 25 '15 at 19:04
• So, no general solutions to this, I guess. My work around has been to export the polygons themselves from COMSOL and then restrict my data output from COMSOL to values at the nodes or faces of those polygons. Not ideal, but perhaps I'm asking for a miracle here. Some Math grad should do their Ph.D. work on this problem for me! – djphd Apr 9 '15 at 2:57

This is easily solved (for geometric primitives and combinations thereof) using DiscretizeRegion, RegionPlot3D, etc.

For example, for the point cloud listed above one can define implicit regions such as

R1 = ImplicitRegion[-1 <= x <= 1 && -2 <= y <= 2 && -.5 <= z <= .5, {x, y, z}]
R2 = ImplicitRegion[x^2 + y^2 <= .25^2 && .5 <= z <= .8, {x, y, z}]


and then visualize them in various ways, such as

shape = RegionUnion[R1,R2]
DiscretizeRegion[shape]


This results in a rather poor discretization near sharp edges which can be improved using the method suggested here

For visualization only, using RegionPlot with the same booleans results in rendering with arbitrary "fineness" given by PlotPoints, and the underlying GraphicsComplex can then be extracted if desired.

RegionPlot3D[(-1 <= x <= 1 && -2 <= y <= 2 && -.5 <=
z <= .5) || (x^2 + y^2 <= .25^2 && .5 <= z <= .8), {x, -2, 2}, {y, -2, 2}, {z, -2, 2},
PlotPoints -> 100]

• Please show the code that solves the problem. – Michael E2 Nov 30 '15 at 1:58
• Is this better? – djphd Nov 30 '15 at 3:13
• Yes, but the solution relies on knowing the equations which the point cloud satisfies, which is surprising to me and seems not in the spirit of the original question. By the way, an easier solution can be written in terms of Cuboid and Cylinder instead of the equations. – Michael E2 Nov 30 '15 at 3:32