•      Sign In
• Create Account

### #Actualjapro

Posted 16 July 2012 - 07:14 AM

Not sure why everyone is so fascinated by working with angles. It usually makes things more complicated.

Anyway a simple collision resolution for this case is to simply offset each ball by half the penetration.
void resolveCollision(Ball &a, Ball &b)
{
vec2 diff = a.position-b.position;
double dist = length(diff);
double penetration = max(0, a.radius + b.radius - dist);
a.position += 0.5*penetration*diff/length;
b.position -= 0.5*penetration*diff/length;
}

Then you just apply that iteratively to all colliding pairs of balls and either have "multi collision" being sorted out over multiple time steps, or iterate this until there is no collisions anymore.
This doesn't handle velocity yet but I didn't really get how you want that resolved anyway? just cancel out relative movement? elastic collision

### #3japro

Posted 16 July 2012 - 07:11 AM

Not sure why everyone is so fascinated by working with angles. It usually makes things more complicated.

Anyway a simple collision resolution for this case is to simply offset each ball by half the penetration.
void resolveCollision(Ball &a, ball &b)
{
vec2 diff = a.position-b.position;
double dist = length(diff);
double penetration = max(0, a.radius + b.radius - dist);
a.position += 0.5*penetration*diff/length;
b.position -= 0.5*penetration*diff/length;
}

Then you just apply that iteratively to all colliding pairs of balls and either have "multi collision" being sorted out over multiple time steps, or iterate this until there is no collisions anymore.
This doesn't handle velocity yet but I didn't really get how you want that resolved anyway? just cancel out relative movement? elastic collision

### #2japro

Posted 16 July 2012 - 07:03 AM

Not sure why everyone is so fascinated by working with angles. It usually makes things more complicated.

Anyway a simple collision resolution for this case is to simply offset each ball by half the penetration.
void resolveCollision(Ball &a, ball &b)
{
vec3 diff = a.position-b.position;
double dist = length(diff);
double penetration = max(0, a.radius + b.radius - dist);
a.position += 0.5*penetration*diff/length;
b.position -= 0.5*penetration*diff/length;
}

Then you just apply that iteratively to all colliding pairs of balls and either have "multi collision" being sorted out over multiple time steps, or iterate this until there is no collisions anymore.
This doesn't handle velocity yet but I didn't really get how you want that resolved anyway? just cancel out relative movement? elastic collision?

### #1japro

Posted 16 July 2012 - 07:03 AM

Not sure why everyone is so fascinated by working with angles. It usually makes thing more complicated.

Anyway a simple collision resolution for this case is to simply offset each ball by half the penetration.
void resolveCollision(Ball &a, ball &b)
{
vec3 diff = a.position-b.position;
double dist = length(diff);
double penetration = max(0, a.radius + b.radius - dist);
a.position += 0.5*penetration*diff/length;
b.position -= 0.5*penetration*diff/length;
}

Then you just apply that iteratively to all colliding pairs of balls and either have "multi collision" being sorted out over multiple time steps, or iterate this until there is no collisions anymore.
This doesn't handle velocity yet but I didn't really get how you want that resolved anyway? just cancel out relative movement? elastic collision?

PARTNERS