Collision of rotated rectangles without pygame

John Nagle nagle at animats.com
Tue Dec 7 03:53:27 EST 2010


On 12/5/2010 2:49 PM, Martin Manns wrote:
> Hello,
>
> I am looking for a Python library for 2D collision checks of rotated
> rectangles. Currently, I have found vizier 0.5b that is based on pygame.
>
> Since I do not want to add a pygame dependency to my app, I replaced the
> pygame.rect.Rect by a wxPython wx.Rect (see code below).
>
> However, collision checks do not work correctly, i. e. identical rects
> are not found to be colliding:

    Probably because you seem to be trying to compute the intersection
point for coincident lines, which is not well-defined.

    I don't have time to debug this, but you might want to get some
basic books on game programming and graphics.

    Incidentally, a dictionary lookup in Python is far more expensive
than computing trig functions.  If you need to speed this up
for large numbers of rectangles, there are algorithms that are
several orders of magnitude faster.  Realistically, though,
this is the kind of problem that runs slow in CPython.

    This is why you don't write your own collision library.
(I once did, for 3D, but that was in 1996, when it was
cutting-edge technology.)

				John Nagle



More information about the Python-list mailing list