1

I don't think this is a duplicate question - at least I hope not.

I have two polygons A and B. B may be entirely inside A or may partly intersect with it. The requirement is to redraw polygon A so that it wraps around Polygon B. I am clear how to handle the case where B is entirely within A. I cut A at the nearest point to B and then insert the points that make up B into the point list for A at the nearest point and add that point again. This should create a flow of A around B. I have plenty of geometry algorithms in my library to calculate distances, bearings and so on but I can't see any of them being helpful Both polygons can be concave, convex etc etc.

My problem comes where B is partially within A. Here I get as far as identifying where the edges of B intersect the edges of A and creating new points in A for those. I then remove any A point that are fully within B since I no longer need them. Here it falls apart. I know the points in B that I need to insert into A. What I don't know is where to insert them or how to work that out.

I have looked at several articles that cover polygon intersection and collision - for example this How to intersect two polygons?.

What I am not clear about is whether I should be looking at this as a way of solving my problem or whether there is something simpler here that I am missing

Community
  • 1
  • 1
ScruffyDuck
  • 2,606
  • 3
  • 34
  • 50
  • Are you examining line segments for both polygons to determine intersection or are you just using some method that returns a list of intersecting points? – Michael Todd Aug 16 '11 at 17:22
  • I am running through the edges (line segments) of B and testing for an intersection with the edges of A. In effect a double for loop – ScruffyDuck Aug 16 '11 at 17:25
  • 2
    Then the place to add the point of intersection to the list of points in the polygon is after the first point on the segment that indicated that there was an intersection. IOW, if A1 and A2 are endpoints on the segment, add the point after A1 and delete A2. Do the same for the other "side" (i.e. line segment) of the polygon that intersects to remove the overlapping area. – Michael Todd Aug 16 '11 at 17:31
  • 2
    i think you must be in a muddle. take a walk round the block to clear your head because this is no harder than what you have already done (i think!). as michael says, just add the "first" intersection, then walk round B adding points to A, until you get to the "second" intersection. the only hard bit is knowing which way to go round B. – andrew cooke Aug 16 '11 at 17:46
  • I am definitely in a muddle but I think you are correct and it is not so hard after all – ScruffyDuck Aug 16 '11 at 20:14
  • I know which way to go round. I want the points from B that are inside A – ScruffyDuck Aug 17 '11 at 06:08
  • @ScruffyDuck if you found a solution, please add it as an answer :) – Christopher Manning Mar 04 '12 at 12:07
  • Sorry I have not worked on this for a while but I will need to get back to it – ScruffyDuck Mar 24 '12 at 10:02

0 Answers0