Skip to main content
gamedev.net
🔒 Locked

best search algorithm

Started by mike_hudson_uk 1 reply 750+ views
Original Post
mike_hudson_uk
mike_hudson_uk
hi all I'm afraid I don't know much about search algorithms and would like a steer in the right direction if you please. I have a system with between 50-100k nodes, distributed pretty much uniformly, some of them joined together as continuous line segments. I'm looking at ways of optimising a scheme to resolve contact between any of the line segments that overlap, and was thinking a good place to start would be the search algorithm that looks for near neighbours. The nodes all lie along a path that I have described parametrically, so I am umming and a-ing about whether to try and use that to my advantage in some way, otherwise just a good fast way of sorting these with a tree would be appreciated. currently i think an ab tree is being used, but I don't even know what that is!-can't find zip with google - possibly just a standard binary tree? your thoughts?
Dave Eberly
Dave Eberly
My preference is a sort-and-sweep algorithm. Create axis-aligned bounding boxes for the edges. Sort phase: Project the boxes onto the x-axis and sort the points, but remembering which are the "begin" and "end" points for the intervals of projection. Sweep phase: Traverse the sorted points and maintain an "active" set of boxes--those for which you have visited the "begin" point, but not the "end" point. Each time you add a box to the active set, all boxes in that set overlap in x. You test pairs of these boxes for overlap in the y-direction. For those pairs that do overlap, you then finally do an edge-edge intersection test. Whenever you read an "end" point for a box, that box is removed from the active set. The expectation is that the active set has a very small number of boxes at any one time, so the dominant part of the algorithm is the sort phase, which is O(n log n) for n edges.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.