# Sphere collision questions.

This topic is 4674 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Im try to implement a very simple sphere collision for particles i dont understand how to calculate the new velocity from 2 colliding objects. My maths is very limited so im having trouble understanding the very basics but i got to start some where. From nehe tutorials lesson 30 - explains how to get the new velocity off 2 colliding spheres
Quote:
 U1y and U2y are the projected vectors of the velocity vectors U1,U2 onto the axis which is perpendicular to the X_Axis. To find these vectors a few simple dot products are needed. M1, M2 is the mass of the two spheres respectively. V1,V2 are the new velocities after the impact, and V1x, V1y, V2x, V2y are the projections of the velocity vectors onto the X_Axis. In More Detail: a) Find X_Axis X_Axis = (center2 - center1); Unify X_Axis, X_Axis.unit(); b) Find Projections U1x= X_Axis * (X_Axis dot U1) U1y= U1 - U1x U2x =-X_Axis * (-X_Axis dot U2) U2y =U2 - U2x c) Find New Velocities (U1x * M1)+(U2x*M2)-(U1x-U2x)*M2 V1x= -------------------------------- M1+M2 (U1x * M1)+(U2x*M2)-(U2x-U1x)*M1 V2x= -------------------------------- M1+M2 In our application we set the M1=M2=1, so the equations get even simpler.
Dont think i follow what he means by the whole x axis thing why do i need to calculate that and wouldnt the axis change ? thx alot for any help, fishy

##### Share on other sites
I think in the example above it assumes the spheres are colliding head on
O---->           <------o     O---<-->--o     <----O o---->

##### Share on other sites

Quote:
 R is the new direction vectorI is the old direction vector before the collisionN is the Normal at the collision point The new vector R is calculated as follows: R= 2*(-I dot N)*N + I

So in theory this would just make me bounce off at a mirror angle ?

So i know at what point the sphere collides ok but how i do i calculate the normal at the collision point ?

##### Share on other sites
When it mentions N is it talking about the face normals or is this some sorta new normal that has to be calculated specifically for collision ?

Just with my particles they are all 2d billboards in 3d space.

##### Share on other sites
When the tutorial says x axis, it means the axis in the direction of the collision. For two spheres, the direction of the collision is the same as the vector from the center of one sphere to the center of the other. The code finds this direction and normalizes it to get what it is calling the x axis, which is really the collision axis. In a frictionless collision, the is the only direction in which the velocities are affected. The velocities perpendicular to this direction are unaffected.

##### Share on other sites
thx for that cleared it up slighty.

Ive implemented the way it says like so,

C = CenterPosB - CenterPosA;

VEC3 Axis;
Axis = Unit_Vec(C);

VEC3 U1, U2;
U1.x = Axis.x * (Axis.Dot_ProductVEC3(VelA));
U1.y = VelA->x - U1.x;
U2.x = -Axis.x * (-Axis.Dot_ProductVEC3(VelB));
U2.y = VelB->x - U2.x;

VelA->x = (U1.x + U2.x - (U1.x - U2.x));
VelA->y = U1.y;

The problem is that all my particles start off from a single spot so i figured they would all bounce all over the place but even with the emission rate as 2 every 10 seconds and with me only checking particle A against B as soon as they collide the velocity of A is reduced to almost zero.

Am i missing something ?

thx again.

Some of the syntax is really confusing i.e.

U1y=ArrayVel[BallColNr1]-U1x; this mean Vel.x - U1x or Vel.y - U1x or something else ><

##### Share on other sites
U1x, U1y, U2x, and U2y are all vectors. This seems to me to be a particularly confusing implementation of a collision response for two spheres...

##### Share on other sites
Sounds very simple aswell ><.

heres the link btw to that guide,
http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=30

Is there a better explination of this any where ?

##### Share on other sites
Wooo i got it to work sorry my stupidity i was calculating the unit vector wrong ><. Was doing *= mag instead of /= im still not fully sure that its working though ill have to go through the code in more detail but for now it does seem to bounce away.

One thing that im still not quite sure on though is what if the collision is in the z axis ? That method seems to only update the x and the y how would you apply this to the z aswell.

##### Share on other sites
A simpler formulation that works in any dimension goes like this:

Let the centers of the spheres be C1 and C2, and let their respective velocities be V1 and V2 and their masses be M1 and M2. e is the coefficient of restitution (0 for an inelastic collision, 1 for an elastic collision, and in between for anything else).

N = C1-C2
V = V1-V2
Impulse = -(1+e)*V*N / N*N*(1/M1 + 1/M2)
V1 = V1 + Impulse/M1
V2 = V2 + -Impulse/M2

For more information on how this is derived, you can look at the third article in Chris Hecker's series of articles on rigid body dynamics, found at http://www.d6.com/users/checker/dynamics.htm

This formulation is more concise, involves fewer operations, and works in 2 or 3 dimensions. Note that all of the quantities involved, except mass and the coefficient of restitution, are vectors.

1. 1
2. 2
Rutin
19
3. 3
khawk
15
4. 4
5. 5

• 13
• 26
• 10
• 11
• 44
• ### Forum Statistics

• Total Topics
633743
• Total Posts
3013644
×