Circle Collision Response

BlitzMax Forums/BlitzMax Programming/Circle Collision Response

Scienthsine(Posted 2005) [#1]
Ehh... been searching the web for some collision response tutorials. Specifically for 2 circles, given their positions, radius...es?, masses, velocities, and point of collision. Taking into account friction and bouncy-ness?

It should be fairly simple, I'm just having trouble finding it due to the large amount of more complex physics stuff out there. Something for billiards/pool would work, as long as it doesn't get into specific billards stuff such as ball rotation. No rotation :p

Found a bit of code laying around here, but would rather have a page or something explaining some of this.

Wish there was a General 2D Programming board for positing this...


Diordna(Posted 2005) [#2]
Here's what you do to determine what angle they bounce off at. Just for the record, it's old code, and I had to change some stuff without testing for it to work the way you want it to, so you might have to tweak some things. Also, it assumes the object you're colliding with is completely stationary, but all you have to do is do it to both one, using the other as reference. As for determining bounce speed, I'd imagine there's something easy enough that combines speed with mass, adds them together, and determines how much speed each one goes away with.

"YOUR VARIABLE HERE" refers to some number that is determined by the part of your code that tells this part of the code how fast to bounce each object off.

It's not in this code, but remember at the end that v1a+v1b>v2a+v2b. This means that the total added velocities at the beginning are greater than those at the end, because almost all collisions lose some energy to heat and whatnot. That should be a start for you.

'vx/vy are the velocity
Local velocityAngle:Double=ATan2(vy,vx)
Local normal:double=atan2(y1-y2,x1-x2)
Local originalVelocity:Double=Sqr(vx*vx+vy*vy)
velocityAngle=normal+(normal-(velocityAngle-360))
vx=Cos(velocityAngle)*originalVelocity*(YOUR VARIABLE HERE)
vy=Sin(velocityAngle)*originalVelocity*(YOUR VARIABLE HERE)


More stuff about rebound velocity: If it were me, I'd have a sort of "point system" in place, where an object gets x points for speed, and y points for mass, and when they collide, you add their points, and divide an individual's points by the whole, and using that as 'YOUR CONSTANT HERE', effectively dividing the energy between the two objects.