Compute union of two arbitrary shapes

后端 未结 6 1951

I\'m working on an application, I need to be able to combine two overlapping arbitrary shapes as drawn by the user. This would be a Union operation on the two shapes. The re

6条回答
  •  北海茫月
    2020-12-30 11:55

    How about:

    1. Pick the left-most point of the two shapes. Call that Shape A and make it the current shape.
    2. Wind clockwise along the current shape to the next point and check to see if one or more lines intersect.
      • If any lines DO intersect, find the first intersection point and add that to your new shape. Switch to winding along the other shape.
      • If no lines intersect move onto the next point in shape A and add that as the point in your new shape. Continue winding along the current shape.
    3. Repeat Step 2.

    I think if you keep winding along whichever shape is current, looking for intersections, that should do what you want. I think that should cope with concave shapes as well...

    I'm sure there are a lot of optimisations you can add once you've got the basics working.

提交回复
热议问题