2
$\begingroup$

I have a volume enclosing a certain region. The region is non-convex, and I calculate its convex hull with the built-in Mathematica function. I want to know the difference between the region and its convex hull. The inbuilt RegionDifference function throws the following error:

BoundaryMeshRegion::bsuncl: The boundary surface is not closed because the edges Line[{... ,<<2390>>}] only come from a single face.

Any help would be appreciated.

(* some preliminaries *)
fn[x_, y_] = 
 x^2 + y^2 + 
  2/x^2 (-20 x + 0.4 x^2 + y^2)^2 (1/2 + (
     Sqrt[
      2] (Cos[(x^2)^(1/4)/Sqrt[2]] - 
        Cosh[(x^2)^(1/4)/Sqrt[2]]))/((x^2)^(
      1/4) (Sin[(x^2)^(1/4)/Sqrt[2]] + Sinh[(x^2)^(1/4)/Sqrt[2]])))
fnLimit[x_, y_] = Limit[fn[x, y], x -> 0]
fnPiecewise[x_, y_] = 
 Piecewise[{{fn[x, y], x < 0}, {fnLimit[x, y], x == 0}, {fn[x, y], 
    x > 0}}]

(* the region of interest *)
volToPlot = 
  ImplicitRegion[
   fnPiecewise[x, y] - 100 z < 
    00, {{x, -300, 300}, {y, -300, 300}, {z, 0, 800}}];
vol = BoundaryDiscretizeRegion[
  volToPlot, {{-300, 300}, {-300, 300}, {0, 800}}, 
  MaxCellMeasure -> 1000]

(* Convex hull of the region *)
convexHullVol = ConvexHullMesh[vol]

RegionDifference[convexHullVol, vol]
$\endgroup$
4
  • 1
    $\begingroup$ "RegionDifference is throwing an error" - what error? $\endgroup$ Commented Jun 1, 2022 at 12:26
  • $\begingroup$ Thanks, @MarcoB. I edited the question. $\endgroup$ Commented Jun 1, 2022 at 12:28
  • $\begingroup$ OpenCascadeShapeDifference can do such difference. mathematica.stackexchange.com/a/299630/72111 $\endgroup$ Commented Mar 9, 2024 at 12:32
  • 1
    $\begingroup$ Needs["OpenCascadeLink`"]; Needs["NDSolve`FEM`"]; shape0 = OpenCascadeShape[vol]; shape1 = OpenCascadeShape[ConvexHullMesh[vol]]; shape = OpenCascadeShapeDifference[shape1, shape0]; reg = OpenCascadeShapeSurfaceMeshToBoundaryMesh[shape, "ShapeSurfaceMeshOptions" -> {"AngularDeflection" -> 0.01}] // MeshRegion $\endgroup$ Commented Feb 11 at 0:38

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.