Group Abstract Group Abstract

Message Boards Message Boards

1
|
4.4K Views
|
6 Replies
|
3 Total Likes
View groups...
Share
Share this post:

RegionUnion of 4 polygons not working in NSolve?

Posted 5 years ago

I have a set of 4 Polygons :

polys = {Polygon[{{0, -2, -2.9}, {0, -1.5, -2.65}, {10, -1.5, -2.65}, \
{10, -2, -2.9}}], 
   Polygon[{{0, -1.5, -2.65}, {0, 0, -2.95}, {10, 
      0, -2.95}, {10, -1.5, -2.65}}], 
    Polygon[{{0, 0, -2.95}, {0, 1.5, -2.5}, {10, 1.5, -2.5}, {10, 
      0, -2.95}}],
   Polygon[{{0, 1.5, -2.5}, {0, 2, -3.5}, {10, 2, -3.5}, {10, 
      1.5, -2.5}}]};

I want to find the intersection between some line and the surface region formed by the polygons:

line = HalfLine[{0, 1, 0}, {1, 0, -.52}];
surface = RegionUnion[polys]

enter image description here

But NSolve does not give any solution:

sol = NSolve[{Element[{x, y, z}, line], 
   Element[{x, y, z}, surface]}, {x, y, z}]

I found a solution by testing for each polygon separately with Or:

sol = NSolve[{RegionMember[line, {x, y, z} ], 
   Or @@ (RegionMember[#, {x, y, z} ] & /@ polys)}, {x, y, z}]

Why does NSolve not work if the polygons are assembled to a single surface with RegionUnion[polys]?

POSTED BY: Erik Mahieu
6 Replies
Posted 5 years ago
POSTED BY: Erik Mahieu

I am baffled too. Last week I had two polyhedra with rational coordinates, whose RegionIntersection was floating-point. One would be led to think that geometric computing is done with floats. Now we see an example that goes in the opposite direction. My personal guess is that computational geometry is a part of Mathematica that has been left unfinished.

POSTED BY: Gianluca Gorni
Posted 5 years ago
POSTED BY: Erik Mahieu

My experience with computational geometry in Mathematica is that I cannot predict in advance which approach will work for a given problem, and I must be prepared to try something else. I don't ask "why" any more.

POSTED BY: Gianluca Gorni
Posted 5 years ago

Thank you Gianluca! This works really well but hard to understand "why" for me. Where did you get this, in the docs?

POSTED BY: Erik Mahieu

It works if you Rationalize the coordinates:

polys = Rationalize@{Polygon[{{0, -2, -2.9}, {0, -1.5, -2.65}, {10, \
-1.5, -2.65}, {10, -2, -2.9}}], 
    Polygon[{{0, -1.5, -2.65}, {0, 0, -2.95}, {10, 
       0, -2.95}, {10, -1.5, -2.65}}], 
    Polygon[{{0, 0, -2.95}, {0, 1.5, -2.5}, {10, 1.5, -2.5}, {10, 
       0, -2.95}}], 
    Polygon[{{0, 1.5, -2.5}, {0, 2, -3.5}, {10, 2, -3.5}, {10, 
       1.5, -2.5}}]};
line = Rationalize@HalfLine[{0, 1, 0}, {1, 0, -.52}];
surface = RegionUnion[polys];
Solve[And[Element[{x, y, z}, line], Element[{x, y, z}, surface]], {x, 
  y, z}]
POSTED BY: Gianluca Gorni
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard