View Full Version : Ball to Ball Collisions

elasolova

01-23-2010, 06:37 PM

Hi,

I am trying to implement 3D ball to ball collisions. Although I know the math to do so, I do not how to use my already defined functions to accomplish this deed. For example, I need to compute the plane that is tangent to both balls at the point of collision. Then I need to take reflections from this plane. I am using a simple vec3f structure to represent position and direction of balls. Any help appreciated.

Ilian Dinev

01-24-2010, 12:02 AM

Composed without testing:

struct Sphere{

vec3 pos;

float radius;

}

struct Plane{

vec3 normal; // a,b,c components

float d;

};

Sphere s1,s2;

vec3 tangentDir = s2.pos-s1.pos;

float tangentLenSq = dot(tangentDir,tangentDir);

float sumRadius = s2.radius+s1.radius;

if(tangentLenSq < sumRadius*sumRadius){ // they hit

float tangentLen = sqrt(tangentLenSq);

Plane result;

result.normal = tangentDir / tangentLen; // normalization

float dist1; // distance of intersection point from s1.pos

dist1 = s1.radius - (sumRadius - tangentLen)*0.5;

vec3 intersectionPoint = s1.pos + dist1*plane.normal;

result.d = -dot(plane.normal,intersectionPoint);

}

Kebbun

07-23-2010, 11:22 PM

One method to do this is

1. check if overlapped

(dist from centre to centre < sum of two radii)

2. relocate spheres so they're just touching

(you can probably do this by forcing positions of centres to be radii sum, knowing linear equation from two centres)

3. calculate dx,dy,dz based on momentum exchange?

Optik

07-29-2010, 08:58 PM

if You have the time and computing power.You could determine the point of contact and apply the impulse along the vector(s) pointing to the centre of each sphere from the contact. This will give you a more realistic collision.

Powered by vBulletin® Version 4.2.3 Copyright © 2018 vBulletin Solutions, Inc. All rights reserved.