1
$\begingroup$

Is there a way to extract the boundary points of a BoundaryMeshRegion?

For instance, let's take the test data

pts = Table[{x, RandomReal[{(x - 3)^2, 9}]}, {x, 0, 4, 0.001}];
ListPlot[pts]

enter image description here

ConvexHullMesh[pts, AspectRatio -> 1]

enter image description here

Ideally I would even want to have only those points at the lower edge of the boundary (that is, those points that represent the function (x - 3)^2).

$\endgroup$
  • 2
    $\begingroup$ The answer to the question in the title is easy: MeshCoordinates@mesh - how to only grab the lower points? That's a bit more complicated I would think $\endgroup$ – Jason B. Feb 16 '17 at 23:21
  • $\begingroup$ That answers the main part of the question. For the second part, I realize that "lower edge" is not well defined and requires manual thresholding. I will accept your comment if you post it as an answer $\endgroup$ – Felix Feb 16 '17 at 23:39
3
$\begingroup$

Using @JasonB.s method, would the equivalent polygon suffice?

pts = Table[{x,RandomReal[{(x-3)^2,9}]},{x,0,4,0.001}];
mesh = ConvexHullMesh[pts];

polygonIndices = MeshCells[mesh, 2]
polygon = GraphicsComplex[MeshCoordinates[mesh],MeshCells[mesh,2]];
polygon //Normal
Graphics[{
    FaceForm[LightGray], EdgeForm[Directive[Thickness[Large],Red]],
    polygon
 }]

{Polygon[{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 25, 27, 29, 31, 35, 34, 33, 32, 30, 28, 26, 24, 23}]}

{Polygon[{{0., 9.}, {0.033, 8.80399}, {0.05, 8.70302}, {0.155, 8.09864}, {0.286, 7.37309}, {0.37, 6.92772}, {0.458, 6.46211}, {0.567, 5.92525}, {0.611, 5.71406}, {0.976, 4.11626}, {1.261, 3.03759}, {1.596, 1.98138}, {1.735, 1.61816}, {1.875, 1.31337}, {1.956, 1.1498}, {2.191, 0.689023}, {2.272, 0.576532}, {2.777, 0.0601964}, {2.901, 0.0130619}, {3.272, 0.0808712}, {3.539, 0.355987}, {3.61, 0.440961}, {3.785, 0.662594}, {3.969, 1.07353}, {3.982, 1.26786}, {3.99, 1.45703}, {4., 1.70252}, {3.998, 4.98624}, {3.997, 5.55114}, {3.995, 6.15607}, {3.983, 8.62608}, {3.974, 8.93544}, {3.949, 8.95805}, {3.707, 8.99464}, {3.645, 8.99709}}]}

enter image description here

Another idea is to use a property:

mesh["BoundaryPolygons"]

{Polygon[{{0., 9.}, {0.033, 8.80399}, {0.05, 8.70302}, {0.155, 8.09864}, {0.286, 7.37309}, {0.37, 6.92772}, {0.458, 6.46211}, {0.567, 5.92525}, {0.611, 5.71406}, {0.976, 4.11626}, {1.261, 3.03759}, {1.596, 1.98138}, {1.735, 1.61816}, {1.875, 1.31337}, {1.956, 1.1498}, {2.191, 0.689023}, {2.272, 0.576532}, {2.777, 0.0601964}, {2.901, 0.0130619}, {3.272, 0.0808712}, {3.539, 0.355987}, {3.61, 0.440961}, {3.785, 0.662594}, {3.969, 1.07353}, {3.982, 1.26786}, {3.99, 1.45703}, {4., 1.70252}, {3.998, 4.98624}, {3.997, 5.55114}, {3.995, 6.15607}, {3.983, 8.62608}, {3.974, 8.93544}, {3.949, 8.95805}, {3.707, 8.99464}, {3.645, 8.99709}}]}

$\endgroup$
  • $\begingroup$ Indeed, that is a nice way of sorting the edge points. The points themselves are then accessible by First[List@@First[Normal[polygon]])]. Thresholding (e.g., on the derivative) can be applied to select the lower edge. $\endgroup$ – Felix Feb 16 '17 at 23:59
1
$\begingroup$
pts = Table[{x, RandomReal[{(x - 3)^2, 9}]}, {x, 0, 4, 0.001}];
mymesh = ConvexHullMesh[pts];
mypts = Select[MeshCoordinates[mymesh], #[[2]] < .899 &];
myboundary = Graphics[{Opacity[0.5], Red, Line[mypts]}, AspectRatio -> 1];
myplot = Plot[(x - 3)^2, {x, 0, 4},
   PlotStyle -> {Opacity[0.5], Blue}];
  Show[myboundary, myplot]

enter image description here

This appears a bit different from the poser's question because of the random generation of initial points.

$\endgroup$
  • $\begingroup$ That is already part of the question. The question was how to extract the boundary points from this object. $\endgroup$ – Felix Feb 16 '17 at 23:44

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.