|
||||||||||||||||||
Add Forum to Favorites | Send Topic To a Friend | View Forum FAQ | Track this topic |
Last Thread Next Thread ![]() |
| Simple Bounding-Sphere Collision Detection |
|
![]() Anonymous Poster |
||||
|
||||
| hie i need some help on how to detect collision between cylinder and box ?? |
||||
|
||||
![]() bargasteh Member since: 10/12/2003 From: Manchester, United Kingdom |
||||
|
|
||||
| Very nice tutorial, but is there any other tutorials to explain collision response for inelastic collisions ?! Thanks |
||||
|
||||
![]() Anonymous Poster |
||||
|
||||
| Nice article, but seems to be a typo. The first condition of Check(3) should be "vv - pv" as it is in the math. |
||||
|
||||
![]() Anonymous Poster |
||||
|
||||
| Don't know if you are still looking at this, but there is a small typo where when calculating the formula for d^2 - r^2 = 0 you say you can solve this using the "determinant" instead of "discriminant" as you say later in the article. Very useful article, though! |
||||
|
||||
![]() dizwax Member since: 7/20/2007 |
||||
|
|
||||
| The code is correct in Check(3) (pv + vv <= 0). It's the math that is wrong. I was having trouble using this code, so I ended up going through all of the math. It turns out I just needed to compute t. I was incorrectly thinking that tmin in the code was the t value. If you're interested in the actual t parameter where the collision occurs, do something like this: // (3) Check if the spheres can intersect within 1 frame if ((pv + vv) <= 0 && (vv + 2 * pv + pp) >= 0) { return false; } // tmp is a term for getting next check into good float range float tmp = -pv/vv; // tmp2 = -D/(4*vv) //(4) Check discriminant float tmp2 = pp + pv * tmp; if (tmp2 > 0) { return false; } // calculate the t value t = tmp - sqrtf(-tmp2/vv); return true; |
||||
|
||||
![]() dmp1ce Member since: 6/27/2003 From: USA |
||||
|
|
||||
| I noticed that the 3rd code snippet didn't work for me when the 3 cases passed. I believe the reason is because you actually divided by -vv instead of vv as stated in the article. If I am correct that would make the last line "return ( pp + pv * tmin < 0 );" instead of "return ( pp + pv * tmin > 0 );" because the inequality needs to be flipped when dividing by a negative number which -vv would be. Thank you for the article! |
||||
|
||||
![]() jonboym Member since: 6/17/2003 From: Derbyshire, United Kingdom |
||||
|
|
||||
| I don't understand how you derived the condition vv + pv <= 0 Be grateful if someone could explain. vv + 2pv + pp >= 0 is easy to understand as its just a straight rearrangement but vv + pv seems to spring from nowhere?? |
||||
|
||||
![]() NightCreature83 Member since: 2/21/2008 From: Leamington Spa |
||||
|
|
||||
| In this code the * operator has been overloaded to mean a dot product right. I have not overloaded star in my vector classes so I need to know if its a dot product or a component wise product. And its always nice to tell people if the operator is overloaded or not when dealing with vectors. |
||||
|
||||
![]() Locutusborg Member since: 5/22/2008 From: Hoorn, Netherlands |
||||
|
|
||||
| Am I wrong in saying that the 2nd check should be: if ( pv <= 0 ) return false; instead of if ( pv >= 0 ) return false; from the math above I understand that it should be negative when the spheres are moving away from eachother. Otherwise, great article, been looking for an understandable one for a long time! |
||||
|
||||
![]() dmitriyd Member since: 4/27/2009 From: florencio-varela |
||||
|
|
||||
| This is method that I use, Its easy to understand, see above: Dmitiy Deordiy. int sphere_collision(VERTEX3D pos1, VERTEX3D pos2,float radius1,float radius2) { //calculate a limit distance (radius1 + radius2) float distance = radius1 + radius2; //make a vector VERTEX3D result = subtract_vector(pos1, pos2); //calculate current distance from two bodies float current_distance = vector_length(result); if(current_distance < distance) return 1; else return 0; } VERTEX3D subtract_vector(VERTEX3D a,VERTEX3D b) { VERTEX3D c; c.x=a.x - b.x; c.y=a.y - b.y; c.z=a.z - b.z; return c; } float vector_length(VERTEX3D c) { return (float)sqrt((c.x * c.x) + (c.y * c.y) + (c.z * c.z)); } |
||||
|
||||
All times are ET (US)![]() |
Last Thread Next Thread ![]() |
|