1. Circle Collision Detection
Condition of circle collision:
When two circles are tangent or intersection, we think that the two circles should begin to collide.
Mathematical representation:
Computer Implementation:
Collision between two circles
Bool collisionbetweencircles (circle C1, circle C2) <br/>{< br/> bool hit; <br/> float distanceofcenter = SQRT (POW (c1.center. x-c2.center.x), 2) + <br/> POW (c1.center. y-c2.center.y), 2); <br/> float distanceofradius = c1.radius + c2.radius; <br/> If (distanceofcenter <= distanceofradius) <br/>{< br/> hit = true; <br/>}< br/> else <br/>{< br/> hit = false; <br/>}< br/> return hit; <br/>}
2. Ball collision
Collision Condition of the ball:
When two balls are tangent or intersection, we think the two balls should begin to collide.
Mathematical representation:
Computer Implementation:
Collision between two balls
Bool collisionbetweensphere (sphere S1, sphere S2) <br/>{< br/> bool hit; <br/> float distanceofcenter = SQRT (POW (s1.center. x-s2.center.x), 2) + <br/> POW (s1.center. y-s2.center.y), 2) + <br/> POW (s1.center. z-s2.center.z), 2); <br/> float distanceofradius = s1.radius + s2.radius; <br/> If (distanceofcenter <= distanceofradius) <br/>{< br/> hit = true; <br/>}< br/> else <br/>{< br/> hit = false; <br/>}< br/> return hit; <br/>}From http://www.cnblogs.com/HelloCG/archive/2009/01/14/1375573.html