I do not understand the way you defined those angle?
I would suggest you use (x,y,z) coordinate.
[img]http://www.phy.ntnu.edu.tw/demolab/phpBB/pics/2_2_collision2d.png[/img]

Assume $\vec{r_a}$ and $\vec{r_b}$ are center of those two balls. And the radius are $R_a,R_b$.
Let $\vec{d}= \vec{r_a}-\vec{r_b}$ which is the relative vector between two centers.
Collision occurred if the length math_failure (math_unknown_error): |\vec{d}|&lt;R_a+R_b :
The next step is to find two components of velocity vectors $\vec{V_a}=(V_{ax},V_{ay},V_{az}),\vec{V_b}=(V_{bx},V_{by},V_{bz})$:
1. velocity components parallel to $\vec{d}=(d_x,d_y,d_z)$ $\vec{V}_{ap}=\vec{V_a}\cdot \vec{d}/|\vec{d}|,\vec{V}_{bp}=\vec{V_b}\cdot \vec{d}/|\vec{d}|$
The time step to move backward $dt=\frac{R_a+R_b-|\vec{d}|}{|\vec{V}_{ap}-\vec{V}_{bp}|}$

Hints: how to calculate inner product $\vec{V_a}\cdot \vec{d}=V_{ax}*d_x+ V_{ay}*d_y+V{az}*dz$

2. velocity components perpendicular to $\vec{d}$ $\vec{V_{an}}=\vec{V_a}-\vec{V_{ap}}, \vec{V_{bn}}=\vec{V_b}-\vec{V_{bp}}$
The above two component will not change before and after collision

You can check out previous posted message. e.g. [url=http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=4.msg9#msg9]How to convert 2D collision into 1D[/url]

Just add one more component (z) if you want to transfer from 2D(x,y)to 3D(x,y,z).

It will be much easier if understand the meaning of inner product between two vectors- Help you find out projection of one vector into another vector.
[/quote]

Thank you very much, but I still have a problem.
I'm not sure that the bounce is correct...

This is my code:
[code]
float[] center1=p1.getCenter();
float[] center2=p2.getCenter();
float[] velocity1=p1.getVelocity();
float[] velocity2=p2.getVelocity();

float dx12 = (center1-center2);
float dy12 = (center1-center2);
float dz12 = (center1-center2);

float dx21 = (center2-center1);
float dy21 = (center2-center1);
float dz21 = (center2-center1);

float distance = (float) Math.sqrt(dx12*dx12+dy12*dy12+dz12*dz12);

if (distance<((r1+r2))){

float[] Va=p1.getVelocityComponent();
float[] Vb=p2.getVelocityComponent();

float[] D={dx12,dy12,dz12};
float[] Db={dx21,dy21,dz21};

float[] Vap= new float;
Vap=Va*D/distance;
Vap=Va*D/distance;
Vap=Va*D/distance;

float[] Vbp= new float;
Vbp=Vb*Db/distance;
Vbp=Vb*Db/distance;
Vbp=Vb*Db/distance;

float diff=(float) Math.sqrt((Vap-Vbp)*(Vap-Vbp)+(Vap-Vbp)*(Vap-Vbp)+(Vap-Vbp)*(Vap-Vbp));

float dt=(r1+r2-distance)/(diff);

float[] Van = new float;
Van=Va-Vap;
Van=Va-Vap;
Van=Va-Vap;

float[] Vbn = new float;
Vbn=Vb-Vbp;
Vbn=Vb-Vbp;
Vbn=Vb-Vbp;

center1-=Va*dt;
center1-=Va*dt;
center1-=Va*dt;

center2-=Vb*dt;
center2-=Vb*dt;
center2-=Vb*dt;

dx12 = (center1-center2);
dy12 = (center1-center2);
dz12 = (center1-center2);

dx21 = (center2-center1);
dy21 = (center2-center1);
dz21 = (center2-center1);

distance = (float) Math.sqrt(dx12*dx12+dy12*dy12+dz12*dz12);
// Unit vector in the direction of the collision
double ax=dx12/distance, ay=dy12/distance, az=dz12/distance;

float[] Vap1= new float;
Vap1=(float) (Va*ax);
Vap1=(float) (Va*ay);
Vap1=(float) (Va*az);

float[] Vbp1= new float;
Vbp1=(float) (Vb*(-ax));
Vbp1=(float) (Vb*(-ay));
Vbp1=(float) (Vb*(-az));

float[] Van1 = new float;
Van1=Va-Vap1;
Van1=Va-Vap1;
Van1=Va-Vap1;

float[] Vbn1 = new float;
Vbn1=Vb-Vbp1;
Vbn1=Vb-Vbp1;
Vbn1=Vb-Vbp1;

float mass1=p1.getMass();
float mass2=p2.getMass();

float[] vaP1=new float;
vaP1=(float) (Vap1 + (1+ed)*(Vbp1-Vap1)/(1+mass1/mass2));
vaP1=(float) (Vap1 + (1+ed)*(Vbp1-Vap1)/(1+mass1/mass2));
vaP1=(float) (Vap1 + (1+ed)*(Vbp1-Vap1)/(1+mass1/mass2));

float[] vaP2=new float;
vaP2=(float) (Vbp1 + (1+ed)*(Vap1-Vbp1)/(1+mass2/mass1));
vaP2=(float) (Vbp1 + (1+ed)*(Vap1-Vbp1)/(1+mass2/mass1));
vaP2=(float) (Vbp1 + (1+ed)*(Vap1-Vbp1)/(1+mass2/mass1));

velocity1=vaP1-Van;
velocity1=vaP1-Van;
velocity1=vaP1-Van;

velocity2=vaP2-Vbn;
velocity2=vaP2-Vbn;
velocity2=vaP2-Vbn;

center1+=velocity1*dt;
center1+=velocity1*dt;
center1+=velocity1*dt;

center2+=velocity2*dt;
center2+=velocity2*dt;
center2+=velocity2*dt;

[/code]

There is some problems with to compute the diff, because sometimes it is NaN...
There is any error in my code?