[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Python and Speed




On Apr 17, 2008, at 11:59 AM, Ian Mallett wrote:
[..]
This is precisely the problem I have run into in one of my in-dev games--iterating over large arrays once per frame. Actually, it is basically a collision detection algorithm--I have two arrays, both containing 3D points. The points in one array must be tested with the points in the other to see how close they are. If they are close enough, there is a collision. Naturally, this means that for every point in one array, the other array must be iterated through and the 3D pythagorean theorem performed to each tested point.

Note this is not the most efficient way to do this, using a partitioned space you may be able to avoid comparing most points with one another most of the time. To do this in 2D you could use quad- trees, in 3D you could use oct-trees. See: http://en.wikipedia.org/wiki/Octree

The easiest way to do this is to find a native library that already performs the operations you need. This seems like a rather uncommon function--I haven't found that which I need.

Note ode already implements efficient 3D collision detection in naive code, I believe pymunk does this for 2D. pyode is a python wrapper for ode.

FWIW, you would get better answers to your problems by asking more specific questions. If you had asked "How do I make collision detection faster?" you would have gotten much better answers than asking "How do I make Python faster?".

-Casey