Broadphase for segments

Started by
1 comment, last by Numsgil 12 years, 6 months ago
I have a segment "soup" (that is, a raw list of segments) produced from one or more (possibly complex (self intersecting)) polygons' edges. I want to implement a broadphase for it that will help me detect potential overlaps between segments. I'll be using this for some basic CSG operations on polygons, like flattening complex polygons to simple polygons, adding holes to polygons, finding the union of two polygons, polygon triangulation, that sort of thing.

Right now I'm using a 1 axis sweep of the segments' AABBs. My main nitpick with this is that it's not great at non-batched queries. For instance, for triangulation, I'm using ear clipping, so I need a way to test a newly created segment against existing edges efficiently. With a sort-n-sweep algorithm you have to do a binary search over the sorted handles, which means it's an O(log n) operation. Which isn't bad but it would be better if that was a constant term (as with some sort of spatial hash implementation).

So my current thinking is to use a spatial hash. A well chosen uniform cell size (say, chosen so that 50% of segments would fit in a single cell) would mean most segments overlap only a few cells, and I think I could make that work efficiently. But I'm wondering if there's some other broadphase scheme that would be better suited to this use case, or if anyone has any relevant experience they could share.
[size=2]Darwinbots - [size=2]Artificial life simulation
Advertisement
Why not use the Bentley-ottmann algorithm? This is an O((n+k).log(n)) algorithm (k intersections, n segments) for finding all intersections between a soup of segments
Because I had no idea it existed! :P Thanks for the link; I'll look at it.
[size=2]Darwinbots - [size=2]Artificial life simulation

This topic is closed to new replies.

Advertisement