且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

计算两个任意形状的并集

更新时间:2023-02-01 23:08:44

正确实现布尔操作并不是微不足道的;幸运的是,有些库已经实现了这种功能。



您使用的是什么语言?如果是C ++,请查看 CGAL ,计算几何算法库。


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 resultant shape would be the silhouette of the two overlapping shapes.

The shapes are stored as a sequence of points in a clockwise manner.

Ideally I'd like an algorithm which will take two arrays of Points (x,y) and return a single array of the resultant shape.

I've been reading Wikipedia on Boolean operations on polygons which mentions the Sweep line algorithm but I can't make the link between this and my goal, alas I'm not a Mathematician.

I'm developing the application in ActionScript 3 but I'm familiar with C#, Java and I can pick my way through C and C++.

Implementing boolean operations correctly is not trivial; fortunately, there are libraries that already implement this functionality.

What language are you using? If it's C++, take a look at CGAL, the Computational Geometry Algorithms Library.