# sep axis theorem & collision response

6 replies to this topic

### #1arctwelve

New Member

• Members
• 4 posts

Posted 05 September 2005 - 05:08 PM

In 2D, using the sep. axis theorem, a collision leaves me with a vector that represents the distance I need to move to get out of collision. this works fine, but I'm not clear on how I apply surface friction and restitution. If I simply project out of collision I have a dead, but very slipperly surface.

Anyone have a code examples of what to do after you have the distance vector of the collision. This is in a Verlet system.

### #2Reedbeta

DevMaster Staff

• 5340 posts
• LocationSanta Clara, CA

Posted 06 September 2005 - 05:16 AM

Do you also have a normal vector for the surface of collision? If so, then you can do friction by dampening the objects' velocities in the directions perpendicular to the normal (this is a little tricky to do in Verlet, since it doesn't have explicit velocities, but just needs a bit of math).

For restitution, move the object out by twice the distance vector (fully elastic collision), or by somewhere between 1 and 2 times the distance vector for partially inelastic collisions.
reedbeta.com - developer blog, OpenGL demos, and other projects

### #3arctwelve

New Member

• Members
• 4 posts

Posted 07 September 2005 - 12:24 AM

Thanks, this is what I ended up with :

public function resolveParticleCollision(p:Particle, sysObj:ParticleSystem):Void {

if (isParticleColliding(p)) {

// the projection vector is also our normal for collision response
var normal:Vector = new Vector(p.mtd.x, p.mtd.y);
normal.normalize();

// get the velocity
var vel:Vector = p.curr.minusNew(p.prev);
var sDotV:Number = normal.dot(vel);

// is the particle moving towards the surface
if (sDotV < 0) {

// compute momentum of particle perpendicular to normal
var velProjection:Vector = vel.minusNew(normal.multNew(sDotV));
var perpMomentum:Vector = velProjection.multNew(sysObj.coeffFric);

// compute momentum of particle in direction of normal
var normMomentum:Vector = normal.multNew(sDotV * sysObj.coeffRest);
var totalMomentum:Vector = normMomentum.plusNew(perpMomentum);

// set new velocity w/ total momentum
var newVel:Vector = vel.minusNew(totalMomentum);

// project out of collision
p.curr.plus(p.mtd);

// apply new velocity
p.prev = p.curr.minusNew(newVel);
}
}
}



### #4Reedbeta

DevMaster Staff

• 5340 posts
• LocationSanta Clara, CA

Posted 07 September 2005 - 03:36 AM

Just curious, but what language is that? It looks a little like a cross between Java and Delphi...
reedbeta.com - developer blog, OpenGL demos, and other projects

### #5nanaki

New Member

• Members
• 1 posts

Posted 07 September 2005 - 08:42 AM

I think you will find this link usefull: http://www.d6.com/us...er/dynamics.htm

### #6.oisyn

DevMaster Staff

• Moderators
• 1842 posts

Posted 07 September 2005 - 09:58 AM

Reedbeta said:

Just curious, but what language is that? It looks a little like a cross between Java and Delphi...

It seems more like JScript (a MS extension to JavaScript that has now been ".NETified"
-
Currently working on: the 3D engine for Tomb Raider.

### #7arctwelve

New Member

• Members
• 4 posts

Posted 09 September 2005 - 07:40 PM

Reedbeta said:

Just curious, but what language is that? It looks a little like a cross between Java and Delphi...

It's Actionscript 2, used in Flash. I like to think of it as Java's retarded little brother.

#### 1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users