0

I am running into another algorithm problem where I need to decide the best approach for completing this.

For a simplistic view, I have 2 polygons (Polygon A and B) that can be either convex or non-convex (concave?) and that are "simple". The polygons will be comprised of either lines or arcs but, the polygons do not loop on themselves. I need to determine if A fully contains B.

My current methodology for determining if Polygon A contains Polygon B would be to see if the bounding box of B was inside A. However, I was getting some issues with this and getting false positives. To save the explanation, my issue is the same issue that this guy was having: https://math.stackexchange.com/questions/2273108/polygon-in-polygon-testing

In one of the answers, you will see a picture of what would result in a false positive. The answer also contained a link to a possible solution: Check if polygon is inside a polygon

I am not quite in favor of the line intersection method because when we deal with arcs, things can get a bit complicated. Although, I am open to still doing the line intersection if someone could post a good answer that makes the intersection with arcs simple.

So, I am asking the community if there is another simpler method to determining if Polygon A full encloses Polygon B and if so, if they could post some resources on how to construct said algorithm?

Edit:

The arcs are represented by circular arcs

philm
  • 797
  • 1
  • 8
  • 29
  • One approach you might explore is to determine if the bounding box of A contains the bounding box of B, *and* if any of the segments of A intersect any of the segments of B. Best of luck. – Bob Jarvis - Слава Україні Mar 19 '18 at 16:36
  • I don't think you can solve this without considering intersection (line-arc and arc-arc), and we can't suggest a "simple" method until we know the method you already have in mind. – Beta Mar 19 '18 at 16:42
  • @Beta Sure thing. For now, let us consider finding the intersection of line-arc and arc-arc as my "method" as it is the best option that I have. I have been considering taking the sweep line algorithm but I am not to sure how that would apply for arcs... – philm Mar 19 '18 at 17:20
  • How are your arcs defined? – Nico Schertler Mar 19 '18 at 19:01
  • Is this a homework/assignment/theoretical work? If not, what are the real world problem parameters (expected input size, required precision, required algorithm speed)? – n. m. could be an AI Mar 19 '18 at 19:07
  • The answer will depend on the type of arcs. And "things can get a bit complicated": you cannot avoid that, your problem is uneasy. –  Mar 19 '18 at 20:44
  • For now, my arcs are being drawn as mutliple line segments. Data structure wise, my arcs contain a start and end node and the arc angle. This is NOT for homework or assignment. My input size is not defined becuase that is dependent on the number of line segments for the polygon. As for precision I am not sure what you mean by this? For the algorithm speed, I want to leave open and I will investigate the speed myself at a later date – philm Mar 20 '18 at 12:18
  • If your arcs are made of line segments, this is just a polygonal case. –  Mar 20 '18 at 12:52
  • @YvesDaoust Yep and this would correspond to your answer, thank you – philm Mar 20 '18 at 17:24

1 Answers1

1

A reasonable approach that will work in all cases is by flattening your curvilinear polygons, i.e. by turning the to plain polygons that represent them to some degree of accuracy. This can be done by recursive subdivision.

Then use a sweepline approach to detect intersections.


Note that you can also use the sweepline method upfront, and decompose the arcs in monotonous sections. Beware anyway that two monotonous arcs that are not in a crossing configuration may intersect anyway.

  • I have been toying with this idea for a little bit. An issue that I have right now is how to handle when the sweep line intercepts the arc at 2 locations – philm Mar 20 '18 at 12:19
  • @philm: this is not possible with monotonous arcs. –  Mar 20 '18 at 12:51
  • Sure thing, I think so far, yours is the best solution so I will accept it and move on – philm Mar 20 '18 at 17:24
  • @philm: you didn't want to say more about what your arcs really are, so we can't help you further. –  Mar 20 '18 at 17:57
  • I am confused about this statement. I am simply modeling the arc as and arc with a start/end node and an arc angle. I am not modeling this as a Spline. Just a simple arc – philm Mar 20 '18 at 19:34
  • @philm: do you mean circular arc ? –  Mar 21 '18 at 07:20
  • Yes, that is what I mean – philm Mar 25 '18 at 03:20
  • @philm: then there is a faster way than by flattening. You should have said it earlier. –  Mar 25 '18 at 15:57
  • Would you be able to update the post with the faster method? I think that I can use it elsewhere in my program – philm Mar 27 '18 at 17:22