Circle to Circle Collision
BlitzMax Forums/BlitzMax Programming/Circle to Circle Collision
| ||
I have been trying with no success to figure out how to deflect a moving circle off of a stationary circle. I have been pouring through all kinds of 2d Vector math and am having problems figuring out this one thing. It's easy to determine if the two circles collide. but once they do I need to calculate the reflection angle. I am using a basic 2d vector type and I have been looking at the Max 2D physics community project. It's becoming a little over whelming.. Is there anyone out there that can help me in a basic way how to do what I want. Thanks for any help... I'm getting a little frustrated. Eric |
| ||
This is perfect, I have used it myself in Blitz: http://freespace.virgin.net/hugo.elias/models/m_snokr.htm |
| ||
Thanks I will work with this....Do you have a small working sample? |
| ||
This was 3D. Assume z to be Y in 2D. Other things to note: each frame you add vx to x and vy to y. That gives you your ball positions... was a large array of types. This assumes 2 snooker balls (a and b) have already collided. Use a simple distance check for collisions between two circles. The code deals with response ie... rebounding correctly. ;ball a pos A_X# = EntityX(ball(a)\object) A_Z#=EntityZ(ball(a)\object) ;ball b pos B_X# = EntityX(ball(b)\object) B_Z# = EntityZ(ball(b)\object) ;store a impact_X_A# = ball(a)\vx# impact_Z_A# = ball(a)\vz# ;store b impact_X_B# = ball(b)\vx# impact_Z_B# = ball(b)\vz# ;calculate impact of a and b impact_X# = impact_X_A# - impact_X_B# impact_Z# = impact_Z_A# - impact_Z_B# ;calculate the new impulse speed impulse_X# = normalise(B_X# - A_X#) impulse_Z# = normalise(B_Z# - A_Z#) ;calculate the new impact speeds impactspeed_X# = (impact_X# * impulse_X#) impactspeed_Z# = (impact_Z# * impulse_Z#) ;multiply impulse by masses impulse_X# = impulse_X# * impactspeed_X# * MASS# * MASS# impulse_Z# = impulse_Z# * impactspeed_Z# * MASS# * MASS# ;place back into equation ball(a)\vx# = ball(a)\vx# - impulse_X# / MASS# ball(a)\vz# = ball(a)\vz# - impulse_Z# / MASS# It is a blitz version of the hugo elias stuff. |
| ||
I hate to ask this, but can someone put this in code that runs... I've very frustrated with this topic and could use some help. It's important that the conservation of momentum is observed. Thanks, Eric |
| ||
Heres a simple 2D Snooker/Pool example I converted to Max ... The main Circle<>Circle collision checking is done via the UpdateBallPhysics() function. You might want to play around with the FRICTION, BALL_MASS, and BALL_RADIUS constants too. |
| ||
Now..Finally something I can play with...Thanks much Jim. |
| ||
cool little program Jim. |
| ||
Sorry to bump this, but I'd like to know how to calculate the force of a collision between two objects in the billiards code. I'm thinking that high-speed head on collisions will cause more damage than slight glances, but I'm no mathematician. :) |
| ||
Anyone? |
| ||
Ignore the force and use the momentum There is a law that says that in a collision the total sum of the momentum is the same before and after the collision. the momentum is given by Try reading this site http://en.wikipedia.org/wiki/Momentum and see if you can make any sense of it |