Math question: Collision detection of polygons

Jim Hurley jhurley at infostations.com
Thu Mar 20 21:02:01 EST 2003


>
>Malte Brill wrote:
>
>Thanks to all of you for replying.
>I really appreciate your help a lot. Even though I start thinking I´m not
>smart enough to code a solution on my own at the moment, you gave me many
>good thoughts to play around with. I guess I need to take some extra lessons
>in math before I play around with the expert stuff. :-)
>
>I have to put working on my codebase aside for a while, as I need to finish
>my current project urgently (deadline is next week and there is a lot of
>work left).
>
>Even though I doubt using polygons (or at last the area of them) is usefull
>for collision detection the way I imagined it, I learned a lot of this
>discussion. I´m still very interested in computing areas of polygons and
>their unions, so if someone happens to set up a stack showing some different
>approaches, I would love to see it.
>
>Again,
>
>thank you. You are great. :-)
>
>Malte


Malte,

As so happens, I got caught up in the challenge of this problem, a 
experience which is obviously  true for many on this list.

I have developed a "concept" stack to test collision detection of 
arbitrarily shaped polygons. I chose triangle to start with, but the 
extension to general polygons is straightforward.

The stack is called "Colliding polygons.rev" and can be found at:

http://home.infostations.net/jhurley/

On the card there are two triangles, a Projectile triangle and a 
Target triangle. You may drag the  "Projectile" triangle about the 
screen. When any portion of the Projectile triangle touches any point 
on the Target triangle you get a beep to acknowledge the contact.

As a second test, there is a button with allows one to fire the 
Projectile triangle at the Target triangle. When they touch at any 
point, the projectile bounces off the target. (There are some 
interesting situations which arise when the bounce causes a second or 
third line intersection.)

The algorithm consists of finding the intersection of all line 
segments. The intersection point for each line segment pair are 
tested to see if they lie within the endpoints of the segments. If 
so, there is contact. (No effort  was made to speed things up with a 
test for nearness.)

(I think it would be much more complex to try to find the onset of a 
union between the two polygons, and much more computer time. But I am 
just guessing.)

Having done this I confess I think it impractical for games. Although 
it does run rather smoothly for these two triangle.

Thanks, Malte, for introducing us to this interesting challenge.

Jim






More information about the use-livecode mailing list