1
$\begingroup$

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.

$\endgroup$
2
  • 4
    $\begingroup$ reg = BoundaryDiscretizeRegion@Vol3; xxx = RandomPoint[reg, 100]; // AbsoluteTiming $\endgroup$
    – cvgmt
    Commented Jun 23, 2023 at 11:00
  • 1
    $\begingroup$ Try: getPt[] := (Until[! MemberQ[Vol1, t = RandomPoint[Vol2]]]; t) $\endgroup$ Commented Jun 23, 2023 at 11:30

1 Answer 1

3
$\begingroup$

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}

enter image description here

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

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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