## Separating Axis Collision Detection

Nibbie
Posts: 1
Joined: 2010.11
Post: #1
Hi,
I've been trying to write a simple separating axis collision detection function between two polygons in C and I can't find any working example code. I don't really care what language it's in, as long as I can run it on my mac and can then port it to C. I'm also simultaneously working on the same thing in Processing, just for testing purposes. You can view the Processing Java Applet here: http://magneon.ath.cx/Test (source file linked from the page) to see what my problem is (the collision is just a little bit off on one side). If anyone has any links or example code lying around I would greatly appreciate it.
Sage
Posts: 1,482
Joined: 2002.09
Post: #2
Nibbie
Posts: 1
Joined: 2010.11
Post: #3
Skorche Wrote:http://www.harveycartel.org/metanet/tuto...rialA.html
Thanks, but that's what I wrote the existing (non-working) code from. I'm kind of looking for a working example so I can see what's wrong with my implementation.
Moderator
Posts: 869
Joined: 2003.01
Post: #4
The logical steps are quite simple. You must create a min and max vector of each polygon, and then you check on each x,y, and z that the intervals (don't) overlap. That's the interval test in words.

The intervals don't intersect if (minA >= maxB) || (minB >= maxA). The common range is from max(minA, minB) to min(maxA, maxB). Hope that makes sense. The code for this is real simple, I can post some if you can't figure it out.
Moderator
Posts: 529
Joined: 2003.03
Post: #5

"Yes, well, that's the sort of blinkered, Philistine pig-ignorance I've come to expect from you non-creative garbage."