3
$\begingroup$

Consider the expression

RandomPoint@
 BooleanRegion[#1 && ! #2 &, {Sphere[{0, 0, 0}], ConicHullRegion[{{0, 0, 0}}, {{1, 1, 1}}]}]

This does not evaluate to a random point in the region (in 12.3), and instead stays unevalauted. However, the argument is both RegionQ and ConstantRegionQ, as required by the documentation:

RandomPoint can generate random points for any RegionQ region that is also ConstantRegionQ.

At first I thought it might be due to the degeneracy of the example, but using RandomPoint @ BooleanRegion[#1 && ! #2 &, {Sphere[{0, 0, 0}], ConicHullRegion[{{0, 0, 0}}, {{1, 1, 1}, {0, 1, 1}, {1, 0, 1}}]}] fails as well. (Yet this BooleanRegion is bona fide: try putting Region in front.)

It doesn't seem to be a problem with BooleanRegion, as e.g. RandomPoint @ BooleanRegion[#1 && ! #2 &, {Sphere[], Ball[{1,1,1}]}] works.

What's happening here, and what's a suitable workaround?

EDIT: Looks like applying DiscretizeRegion before RandomPoint works! But why doesn't RandomPoint evaluate as expected?

$\endgroup$
1
  • $\begingroup$ In short it doesn’t know how to find them for this region so it comes back unevaluated. Discretizing gives a different region (but close approximation) and RandomPoint knows how to work with meshes. $\endgroup$
    – Greg Hurst
    Commented Aug 1, 2021 at 1:30

1 Answer 1

2
$\begingroup$

Update

I found an example to show the limitation of RegionIntersection.

reg = RegionIntersection[Circle[{0, 0}, {5, 4}], 
   Circle[{0, 0}, {2, 8}]];
(* EmptyRegion[2] *)
RandomPoint[reg]
dreg = RegionIntersection[DiscretizeRegion@Circle[{0, 0}, {5, 4}], 
   DiscretizeRegion@Circle[{0, 0}, {2, 8}]];
RandomPoint[dreg]

RandomPoint[EmptyRegion[2]]

{-1.76789, 3.73945}

Original

Maybe ConicHullRegion is numeric and Sphere is symbolic, so they need to coordinate. The last result seems depend on the structure of discretize region.

SeedRandom[1];
BooleanRegion[#1 && ! #2 &, {Sphere[{0, 0, 0}], 
   Line[{{0, 0, 0}, {1, 1, 1}}]}] // RandomPoint
RegionDifference[Sphere[], 
  Triangle[{{0, 0, 0}, {1, 1, 1}, {2, 1, 1}}]] // RandomPoint
RegionDifference[Sphere[], 
   ConicHullRegion[{{0, 0, 0}}, {{1, 1, 1}, {2, 1, 1}}]] // 
  DiscretizeRegion // RandomPoint

{0.245529, -0.968234, 0.0473094}

{-0.528872, 0.54312, -0.652162}

$\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.