Skip to main content
gamedev.net
🔒 Locked

Sphere collision algorithm

Started by awishformore 2 replies 1.5k views
Original Post
awishformore
awishformore
Referring to my first topic on this board about a collision detection for a huge number of spheres with different radius:

http://www.gamedev.net/community/forums/topic.asp?topic_id=507622

I've been working on that problem on and off during the past few years.

I've considered reduction of the problem to 2 dimensions, but this isn't practical due to high clustering of spheres around the origin that my application will have.

I've considered problem division into each dimension and then comparing the results, but it turned out to be too expensive if you have a huge space to deal with, too.

Finally, I came back to my initial approach. I divide the space into fixed size cubes (sections) and only spheres inside a section are tested against each other. For each tick, I have to check when a sphere enters and leaves a new section, but I do this on each coordinate separately , so the problem division comes into play after all. Of course, whenever a sphere is in 2 sections, it will be included in both computations. In order to allow for completely fair collisions, it would be preferable to just treat both these sections like they were a single one. This means that the sections shouldn't be too big if you don't want clustering of sections too become too expensive. As the spheres get bigger, though, you also need bigger sections to avoid too much clustering. I guess the key lies in finding the right section size, so I will probably start experimenting with variable size sections (probably with an octree approach) for fine-tuning. Additionally, I can put another check into each section, for instance by reducing the problem to 2D inside each section, which might make section clustering have less of an impact on performance.

Anyway, any kind of advice or additional inspiration is more than welcome. I will keep you updated on the final approach.

As it currently looks, it's reasonable to assume that the number of separate entities will be somewhere around 100,000 as a maximum, so I will definitely be able to realize my goal.
hplus0603
hplus0603
First: You should realize that if you have N spheres, if they all cluster so they overlap, the solution will contain N-squared terms, so it's not theoretically possible to run faster than N-squered in this worst case.

Second: This is a very well researched area. If you've worked on it for years, I'm surprised you haven't found good references. The terms I'd suggest you google for are:

"Spatial Partitioning"
"Spatial Index"
"Broad-phase Collision Detection"
"Sweep and Prune"
"Loose Octree"
"Hash Grid"

If the spheres are roughly the same size, or at least have a defined upper limit on the size, a hash grid will work very well. If they are very different in size, a loose octree is probably best.
enum Bool { True, False, FileNotFound };
awishformore
awishformore
Quote:
"Loose Octree"
"Hash Grid"

If the spheres are roughly the same size, or at least have a defined upper limit on the size, a hash grid will work very well. If they are very different in size, a loose octree is probably best.

This is the kind of advice I was looking for. My experience as far as practicality and actual performance in my scenario is very limited, so I go on trial and error.

I will do some in-depth reading-up on both of these methods and implement them for side-by-side testing. I'll let you know how it went, but it might take a while since I'm currently busy working on the client-side application.

Greets, Max.
awishformore
awishformore
Hey there.

I just found this paper on hash grid collision detection:

http://www10.informatik.uni-erlangen.de/Publications/Theses/2009/Schornbaum_SA09.pdf

It describes an algorithm that is no less than perfect for my purposes. At the same time, it's very close to my collision detection algorithm already and I will only need to make rather minor changes (basically, the only difference in how it works is the mapping part to a fixed size hash grid instead of an infinite size grid where the cells are distributed all over space).

Thanks for the hints and take care.

[Edited by - awishformore on June 21, 2010 6:22:08 PM]

Topic Locked

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

Sign in to reply to this topic.