This topic is 2611 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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.

##### Share on other sites
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

##### Share on other sites
Because I had no idea it existed! Thanks for the link; I'll look at it.

1. 1
2. 2
Rutin
19
3. 3
khawk
15
4. 4
5. 5
A4L
13

• 13
• 26
• 10
• 11
• 44
• ### Forum Statistics

• Total Topics
633744
• Total Posts
3013652
×