1
$\begingroup$

I programmatically generate a shape, where the top surface is defined by a series of polygons. I generate all the points of the polygon.

polygonCoord = 
  N[ToExpression[
     Import["https://pastebin.com/raw/1TqJ9xRs", "List"]][[1]]];

poly = Polygon[polygonCoord];

(*this looks great*)
Graphics3D[poly, Axes -> True]

(*and I can create a Mesh object, with Region Dimension 3, no problem*)


DelaunayMesh[Flatten[polygonCoord, 1]]

Graphics 3D and the Mesh object look great:

enter image description here enter image description here

For a concave shape, it doesn't work

polygonCoord = 
  N[ToExpression[
     Import["https://pastebin.com/raw/TH3yTHH7", "List"]][[1]]];

poly = Polygon[polygonCoord];

(* this looks great *) 
Graphics3D[poly, Axes -> True]

(* but I have no way to create a Mesh, from which I can use useful \
functions like RegionDistance[] and RegionNearest[] in Region \
Dimension 3 *) 

DelaunayMesh[Flatten[polygonCoord, 1]]
ConvexHullMesh[Flatten[polygonCoord, 1]]

Graphics 3D looks good:

enter image description here

But the Mesh Object doesn't work:

enter image description here

Any ideas how I can use the polygon coordinate data to create the shape I want?

$\endgroup$
1
  • 2
    $\begingroup$ Maybe this can help: (86277), (38178). Include also the word "alpha-shape" to your list of search keywords. $\endgroup$ Commented May 7, 2020 at 12:46

1 Answer 1

4
$\begingroup$

Since both DelaunayMesh and ConvexHullMesh work on convex shapes, you probably should not expect them to work on concave shapes. You could split out the first 5 coordinate groups representing the base and do a difference operation with the rest of the points.

polygonCoord = 
  N[ToExpression[
     Import["https://pastebin.com/raw/JYeSyxyp", "List"]][[1]]];
regbase = DelaunayMesh[Union@Flatten[polygonCoord[[1 ;; 5]], 1]];
regshape = DelaunayMesh[Union@Flatten[polygonCoord[[6 ;; -1]], 1]];
regdiff = RegionDifference[regbase, regshape]

enter image description here

$\endgroup$

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