Archived

This topic is now archived and is closed to further replies.

Seperating Axis collision detection

This topic is 5008 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I have implemented the seperating axis collision detection algorith, including tracking of what sections of the polygon are involved in the collision. But I am having one problem, when the polygons are already overlapping when, I don''t know how to track what elements are involved in the collision. I am just wondering how other people have solved this? My idea was to move backwards in time and find the point when the objects seperate, then use those edges/points as the elements.

Share this post


Link to post
Share on other sites
you can do that, or I tried another way, which was to take the minimum overlap distance found on the set of axes, and use that as my collision plane. so it gives me the normal, and penetration depth. It''s pretty accurate, if the objects are not deeply embedded (which is always a problem anyway).

the overlap distance for each axes is simple the amount of interval overlap along an axis, which gets re-normalised so I can compare them in a meaningful way. Take the non-zero axis with the minimum overlap distance, and use that as a collison plane.

Share this post


Link to post
Share on other sites
when you test the axes, the axes are not normalised. so the intervals are stretched by the axes length. so to compare the intervals to find the minimum, you divide the separation axis by it''s length, and also the interval.



bool BoxBoxCollide(COBBox Box1, COBBox Box2, Vector& Ncoll, float& dcoll)
{
// the 15 separation axes, and the corresponding interval intersection

Vector Axis[15];
float min0[15], max0[15], min1[15], max0[15];
float depth[15];

// that''s the standard separation axis test, which fills the two arrays

if (BoxBoxSeparated(Box1, Box2, Axis, min0, max0, min1, max1))
return false;

// calculate the interval intersections span

for(inti = 0; i < 15; i ++)
{
float min = (min0[i] > min1[i])? min0[i] : min1[i];
float max = (max0[i] < max1[i])? max0[i] : max1[i];
depth[i] = max - min;
}

// now, find the best guess for the collision plane among the separation axes.

// will be the separation axis where the interval intersection is minimal

float min = -1;
for(int i = 0; i < 15; i ++)
{
// length of axis

float d = Axis[i].GetLength();

// separation axis is degenerate. not usable as a collision plane

if (d < 1.0fE-8)
continue;

// normalise depth

depth[i] /= d;

// first valid axis. use it for the moment

if (min == -1)
{
min = i;
Axis[i] /= d;
continue;
}

// found a minimum axis

if (depth[i] < depth[min])
{
Axis[i] /= d;
min = i;
}
}

// error...

if(min == -1) return false;

Ncoll = Axis[min];
dcoll = depth[min];

// make sure the normal faces the right way

Vector D = Box1.Centre - Box2.Centre;
if (D * Ncoll < 0.0f)
Ncoll *= -1.0f;

return true;
}

Share this post


Link to post
Share on other sites