5

Bug introduced in 12.1 or earlier and persisting in 13.2.1


I have a flat 3D-Polygon (all points have the same z-Value) and a 3D-line, which I need to check if they intercept using RegionDisjoint. Assume this:

line = {{-7, 100, 42}, {0, 15, 10}};
poly = {{-(49/10), 266/5, 43/2}, {-(89/10), 47, 43/2}, {-(54/5), 85/2,
 43/2}, {-(62/5), 217/5, 43/2}, {-(88/5), 499/10, 43/
2}, {-(183/10), 487/10, 43/2}, {-(211/10), 221/5, 43/
2}, {-(17/10), 162/5, 43/2}, {69/10, 459/10, 43/2}, {-(22/5), 53, 
43/2}};
RegionDisjoint[Line[line], Polygon[poly]]
Graphics3D[{Line[line], Polygon[poly]}]

This doesn't evaluate. It just returns this:

enter image description here

When I simply remove one random point of the polygon or move it up above the end of the line (z-coordinate >43/2) it suddenly evaluates. This example:

poly2 = poly*2;
RegionDisjoint[Line[line], Polygon[poly2]]

returns True. What am I doing wrong here?

Mathematica 12.1 on Windows 11

cvgmt
  • 72,231
  • 4
  • 75
  • 133
Christoph T.
  • 115
  • 6
  • 4
    As a workaround, RegionIntersection[Line[line], Polygon[poly]] returns a point in your case, indicating that there is an intersection. Perhaps you could could use that return value as a stop gap measure. – MarcoB Jan 14 '22 at 15:07
  • 1
    Something is odd though: RegionDisjoint[Line[line], Polygon[poly], GenerateConditions -> True] returns an error: "RegionDisjoint::reg: GenerateConditions->True is not a correctly specified region.". That is unexpected! I wonder if something is going awry within RegionDisjoint then. – MarcoB Jan 14 '22 at 15:13
  • 2
    It also works for InfiniteLine, i.e., RegionDisjoint[ InfiniteLine[line], Polygon[poly]] evaluates to False – Bob Hanlon Jan 14 '22 at 16:03

1 Answers1

3

It seems be a bug. By now we have to solve it manually.

poly = {{-(49/10), 266/5, 43/2}, {-(89/10), 47, 43/2}, {-(54/5), 85/2,
     43/2}, {-(62/5), 217/5, 43/2}, {-(88/5), 499/10, 
    43/2}, {-(183/10), 487/10, 43/2}, {-(211/10), 221/5, 
    43/2}, {-(17/10), 162/5, 43/2}, {69/10, 459/10, 43/2}, {-(22/5), 
    53, 43/2}};
line = {{-7, 100, 42}, {0, 15, 10}};
Solve[{x, y, z} ∈ Polygon[poly] && {x, y, z} ∈ 
   Line[line], {x, y, z}]

Reduce[{RegionMember[Polygon[poly]]@{x, y, z}, RegionMember[Line[line]]@{x, y, z}}, {x, y, z}]

FindInstance[{{x, y, z} ∈ Polygon[poly] , {x, y, z} ∈ Line[line]}, {x, y, z}]

{{x -> -(161/64), y -> 2915/64, z -> 43/2}}

Graphics3D[{Line[line], Polygon[poly], Red, 
  Ball[SolveValues[{x, y, z} ∈ 
      Polygon[poly] && {x, y, z} ∈ Line[line], {x, y, z}]]}]

enter image description here

We can define a regionDisjoint to do this.

regionDisjoint[reg1_, reg2_] := 
 If[Reduce[{RegionMember[reg1]@{x, y, z}, 
     RegionMember[reg2]@{x, y, z}}, {x, y, z}] === False,True,False];

regionDisjoint[Line[line], Polygon[poly]]

regionDisjoint[Line[line], Polygon[2poly]]

False

True

or define

regiondisjoint = 
 If[RegionIntersection[#1, #2] === EmptyRegion[3], True, False] &
regiondisjoint[Line[line], Polygon[poly]]
regiondisjoint[Line[line], Polygon[2poly]]

False

True

cvgmt
  • 72,231
  • 4
  • 75
  • 133