I know Q3 + Q4 = 90
I searched internet and many physic topics, but not found how to calculate this values in Java?
(I found V3 and V4 but not found Q3 and Q4)
So how can i calculate V3, V4, Q3, Q4 values after the collision in Java?
So, you want the angle of velocity relative to the x-axis? That'd be
atan(V4.y/V4.x) for Q3 and Q4, respectively.
Though, since the balls are almost aligned along the y-axis in relation to each other, it looks like maybe you're looking for the angle of V3/V4 relative to the surface at the point of impact, even when that doesn't line up with the x-axis.
In that case, you need the normal of impact (most collision functions will give you this as some of the output, but it's easy for spheres/circles anyway -- just normalise
ball1.xy - ball2.xy). Anyway, you can use that normal and V3 to calculate Q3 like so:
It'll vary a little depending on what libraries you're using, but basically: the dot product of two normalised vectors (that is, vectors with a magnitude of 1) will be the cos of the angle between the vectors. Apply the inverse cos function (acos) and you get the angle between them.
For Q4, replace "V3" with "V4".
It's much simpler than you think:
Just use the "relative velocity" to calculate the impulse
relVel = vB - vA;
Then, use it to project against the normal to find the impulse.
normal = (posB-posA) / Length(posB-posA); coefficient_of_restituition = 0; // (100% energy lost) coefficient_of_restituition = 1; // (0% energy lost) impulse = -(1 + coefficient_of_restituition) * dot(relVel, Normal) / (invMassA + invMassB);
maby this can help you http://en.wikipedia.org/wiki/Coefficient_of_restitution there is a break down of the entire problem