I have a volume in 3-space in which random spheres are spawned in motion. They have the following attributes to them:
- position known (in three axes)
- a direction vector (in three axes)
- a scalar speed
- a radius (all radii are equal)
I can determine if a collision is made from objects position and radius using the below formula:
d=√(x2−x1)2+(y2−y1)2+(z2−z1)2−2r
If d=0, then a collision has happened. What I want to know is how to determine the new direction vector after impact. I'm not working with angles.
I considered that if spheres A and B collided, and Ax>Bx, then A is to the right of B, thus the new direction of movement for A would be Dx=−Doldx, same thing for B, but I'm not sure if this is entirely correct.
If it makes a difference, there's no air resistance or friction.
Answer
Consider the motion of the two spheres in their center of mass frame: that is, the frame of reference moving at a velocity
→vf=→v1+→v22
Subtract that velocity from the "stationary world" coordinates; then perform the analysis below. Finally, add that velocity back to the result.
At the moment the two spheres touch, draw a line between their centers. Along that direction their velocities are reversed; the other component of their velocity (perpendicular to that axis) is unchanged.
So if particle 1 has initial vector →v1, and the direction of the line connecting the centers at the moment of collision is →r (normalized), then the velocity along the connecting line is
→v1a=(→v1⋅→r)→r
and the velocity perpendicular to the connecting line is
→v1p=→v1−→v1a
After collision, the "along" velocity is reversed, and the new velocity is
→vafter=→v1p−→v1a=→v1−2→v1a
No comments:
Post a Comment