# How to generate a random point inside this region/discretize it?

Consider the following region:

theta[\[Eta]_] = 2*ArcTan[Exp[-\[Eta]]];
zConicalFrustum[z1_, z2_, \[Theta]_] :=
ConvexHullMesh[
Join @@ (Map[Append[#],
CirclePoints[# Tan[\[Theta]], 100]] & /@ {z1, z2})]
fout = zConicalFrustum[10, 18, theta[2.]];
fin = zConicalFrustum[10, 18, theta[5.]];
Dvol = RegionDifference[fout, fin];
Region[Style[Dvol, Opacity[0.1]], BoxRatios -> {1, 1, 1}, Boxed -> True, Axes -> True]


Its intersection with the plane

plane = Polygon[{{3/2, -3/2, 18}, {3/2, 3/2, 18}, {-3/2, 3/2, 18}, {-3/2, -3/2, 18}}];


is

regInt=RegionIntersection[Dvol, plane]


Next, I want either to discretize it or generate random points belonging to it. However, I fail both of these tasks:

DiscretizeRegion[regInt, MaxCellMeasure -> MaxCellMeasureVal]]


DiscretizeRegion was unable to discretize the region BooleanRegion

RandomPoint[regInt, 3*10^4]


Argument RegionMeshCrossingCount at position 1 should be a rank 1 tensor of machine-size integers

Could you please help me with either of these tasks?

• You code does not evaluate, what is theta? Feb 24, 2023 at 10:59
• @user21 : excuse me, I have added the missing definition. Feb 24, 2023 at 11:18
• Both of the solid and the polygon have the same height 18, and the polygon only the part of the upper disk, so the intersection of the two objects only the original polygon remove the center small disk. Feb 24, 2023 at 11:56
• Is there some more general problem that you need to solve? Given @cvgmt 's comment and your desired region is just a square with a circular hole in it, is there something else? Squares at differ heights and/or sizes and/or orientations in the Dvol region?
– JimB
Feb 25, 2023 at 6:30

## 1 Answer

Here is a dirty way to do it:

Needs["NDSolveFEM"]
Needs["OpenCascadeLink"]

theta[\[Eta]_] = 2*ArcTan[Exp[-\[Eta]]];
zConicalFrustum[z1_, z2_, \[Theta]_] :=
ToBoundaryMesh[
"Coordinates" ->
Join @@ (Map[Append[#],
CirclePoints[# Tan[\[Theta]], 100]] & /@ {z1, z2})]
fout = zConicalFrustum[10, 18, theta[2.]];
fin = zConicalFrustum[10, 18, theta[5.]];
(*Dvol=RegionDifference[fout,fin];*)

s1 = OpenCascadeShape[fout];
s2 = OpenCascadeShape[fin];
s3 = OpenCascadeShapeDifference[s1, s2];
plane = Polygon[{{3/2, -3/2, 18}, {3/2, 3/2, 18}, {-3/2, 3/2,
18}, {-3/2, -3/2, 18}}];
s4 = OpenCascadeShape[plane];
s5 = OpenCascadeShapeIntersection[s3, s4];
bmesh = OpenCascadeShapeSurfaceMeshToBoundaryMesh[s5];

bmesh["Wireframe"]
`

A much, much better way to do this is to make a definition of the frustum that uses a region union of a Cone and a Cuboid to delimit the frustum. As an alternative you could use the two circles and loft the frustum.