# How to select the points that belong to the given region?

Consider two regions:

Vol1 = Region@Cylinder[{{0, 0, -26.5}, {0, 0, 26.5}}, 11.3];
Vol2 = Region@
RegionProduct[
Annulus[{1.7, 1.8}, {0.001, 20}, {ArcSin[-(28.7/(2*20))] + Pi/2,
ArcSin[28.7/(2*20)] + Pi/2}], Line[{{-26.5}, {26.5}}]];


I would like to generate points that belong to the region difference:

Vol3=RegionDifference[Vol2,Vol1]


However, this is very slow:

xxx = RandomPoint[Vol3]; // AbsoluteTiming


takes 2 seconds. So I am thinking of generating the points belonging to Vol2 and then leaving only those not belonging to Vol1.

Could you please tell me how to do this? Or maybe it may be possible to speed up generating the random points belonging to Vol3.

Edit

Maybe I may use RegionMember. For the regions Vol1, Vol2, it is even compilable.

• reg = BoundaryDiscretizeRegion@Vol3; xxx = RandomPoint[reg, 100]; // AbsoluteTiming Commented Jun 23, 2023 at 11:00
• Try: getPt[] := (Until[! MemberQ[Vol1, t = RandomPoint[Vol2]]]; t) Commented Jun 23, 2023 at 11:30

The faster way to get the random points seems at first RegionDifference in 2D,then RegionProduct to 3D.

Clear["Global*"];
reg2d = RegionDifference[
Annulus[{1.7, 1.8}, {0.001, 20}, {ArcSin[-(28.7/(2*20))] + Pi/2,
ArcSin[28.7/(2*20)] + Pi/2}], Disk[{0, 0}, 11.3]] //
BoundaryDiscretizeRegion;
reg3d = RegionProduct[reg2d, Line[{{-26.5}, {26.5}}]];
{reg2d, reg3d, reg3d // Region}


pts = RandomPoint[reg3d, 10^4]; // AbsoluteTiming
`