0
\$\begingroup\$

I am looking for algorithm to merge lots of relatively small 2d polygons to one or some big polygons. In case two small polygons are touching or overlapping, they should be merged to one polygon.

My big goal is to sufficiently decrease amount of points/lines required to describe collider. Resulting collider can include some polygons, btw.

Could you propose an algorithm or library to do this? (Finally I will implement solution in C# for Unity3d).

P.S. Here is one picture of task I need to solve. Look this http://epsiloncool.ru/i/E20160624-224050.png Green lines is a colliders. I need to merge them all to get one collider (or some)

\$\endgroup\$
5
  • 1
    \$\begingroup\$ Wouldnt convex hull suffice for collider? It is much easier to calculate convex hull than merging/ordering/intersecting complex shapes. \$\endgroup\$
    – wondra
    Jun 24 '16 at 16:46
  • \$\begingroup\$ Thanks, I didn't thought about it. Could you tell what is the best way to calculate convex hull ? \$\endgroup\$ Jun 24 '16 at 17:57
  • \$\begingroup\$ @wondra Well, I read some docs and I think convex hull not quite the thing I need. I need to simplify colliders by removing internal boundaries. Look this epsiloncool.ru/i/E20160624-224050.png Green lines is a colliders. I need to merge them all to get one collider (or some) \$\endgroup\$ Jun 24 '16 at 18:28
  • 1
    \$\begingroup\$ It looks like none of them can overlap and you know which ones are next to each other, moreover it looks you could get info about "common" vertices from generation process - is that all correct? \$\endgroup\$
    – wondra
    Jun 24 '16 at 19:27
  • \$\begingroup\$ @wondra Correct, it simplifies this task. But actually I'd like to find something more common. \$\endgroup\$ Jun 24 '16 at 19:31
0
\$\begingroup\$

I've been proposed for using awesome Clipper library. It is exactly the thing I need.

"For constructing the union of 2D polygons you can use Clipper library."

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Please, mark this question as answer \$\endgroup\$
    – Bálint
    Oct 15 '16 at 5:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.