# Velocity vector

1. May 11, 2010

### khalsa

Hi, I am trying to simulate a collision. A particle falls down on a sphere and a collision between sphere and particle takes place. The sphere always remain stationary and the collision itself is not elastic.I was trying to set the velocity of particle to be zero after the collision. But that does not give good simulation when the collision does not occur on top of sphere but along the side of sphere.

So now after the collision i need to make sure that the particle has a velocity which is orthogonal to the vector of the point of collision from the center of sphere. The velocity along the vector from center of sphere to point of collision should become zero. How do i do that?

I am a bit mathematically challenged but i think it has something to do with dot product of vectors. Or maybe i am wrong :)

Thanks

Edit: You can check the image describing the collision at http://www.freeimagehosting.net/image.php?c5ae01b476.jpg

Last edited: May 11, 2010
2. May 11, 2010

### mikeph

There is an immediate problem in conversation of momentum in the horizontal direction. If the sphere remains stationary the particle cannot move sideways. You could perhaps bend the rules and claim an equal collision occurs on the other side of the sphere to alleviate this problem.

I also do not understand why you think the particle will move along a tangent to the sphere. Assuming there is no deformation, the collision will occur at a point, and the surface of a sphere can, at a point, be approximated to a flat surface. So the particle will bounce such that the angle of incidence to the normal is the same as the angle at which it departs from the surface, like the reflection of light from a mirror.

3. May 11, 2010

### khalsa

I cant reflect it like light because i want a damp(with loss) collision. So had the particle collided with the sphere right on the top of sphere, its velocity would have been zero. Only when it strikes the sphere on the side will it have some residual velocity along the tangent

Last edited: May 11, 2010
4. May 11, 2010

### diazona

I have a feeling I've calculated this before, but I couldn't find it... anyway: you could calculate the dot product of the initial velocity vector with a unit vector tangent to the sphere (in the direction of the new velocity) and use that as the magnitude of the new velocity vector. Or alternatively, it would be
$$\vert\vec{v}_f\vert = \vert\vec{v}_i\vert \sin\theta$$
where $\theta$ is the angle from the top of the sphere (as in your image) to the point of impact.

5. May 11, 2010

### khalsa

Thanks for the reply.
But only things that i know at the time of collision are the velocity vector of the particle and the 'rvector' which runs along the radius from the point of collision

6. May 11, 2010

### diazona

By 'rvector' do you mean the vector which points from the center of the sphere to the point of impact? If that's the case, the formula I gave can be expressed as
$$\vert\vec{v}_f\vert = \vert\vec{v}_i\vert\sqrt{1 - \frac{(\vec{r}\cdot\vec{v}_i)^2}{(\vec{r}\cdot\vec{r})(\vec{v}_i\cdot\vec{v}_i)}$$

7. May 11, 2010

### diazona

Or, now that I think about it, if you wanted the final velocity as a vector (magnitude and direction), it should be just a matter of subtracting off the component parallel to the radius:
$$\vec{v}_f = \vec{v}_i - \frac{\vec{r}\cdot\vec{v}_i}{\vec{r}\cdot\vec{r}}\vec{r}$$

8. May 11, 2010

### khalsa

Thanks diazona for reply.
My original pseudo code was:-
Code (Text):
foreach (particle particle in particlesCollections)
{
//sphere.x, sphere.y sphere.z give the center of the sphere
dist = particle.pos - vector(sphere.x, sphere.y, sphere.z);

//detect if a collision has taken place.
if (dist.mag < sphere.radius)
{
rVector = dist / dist.mag * sphere.radius;
particle.pos = vector(sphere.x, sphere.y, sphere.z) + rVector;

//particle.Velocity gives the velocity vector of the particle at the time of collision
//i need to modify particle.Velocity so that the component of velocity that runs along
// with the rvector becomes zero as i have a non elsatic collision. The remaining
//velocity that the particle will have is the one which runs along with tangent to the
//rVector. The sphere remains stationary.
//example values: particle.Velocity == <-1.03054, -1.56563, .006>
//and rVector = <2.04406, 2.19587, 1.0514>
}
}
Now after implementing the logic u gave it would be:-
Code (Text):
foreach (particle particle in particlesCollections)
{
//sphere.x, sphere.y sphere.z give the center of the sphere
dist = particle.pos - vector(sphere.x, sphere.y, sphere.z);

//detect if a collision has taken place.
if (dist.mag < sphere.radius)
{
rVector = dist / dist.mag * sphere.radius;
particle.pos = vector(sphere.x, sphere.y, sphere.z) + rVector;
particle.velocity = particle.velocity - (dot(particle.velocity, rVector) / dot(rVector, rVector)) * rVector;

}
}
Is my understanding correct?

Last edited: May 11, 2010
9. May 11, 2010

### diazona

Why, is there something you think is wrong with it?

By the way, when you asked this on StackOverflow you initially phrased it as a physics question, which is why it got closed (also because there's no point asking the same question in two places concurrently). But at this point, if you have specific problems with the code, then you can ask those on SO.

10. May 11, 2010

### khalsa

first of all thanks for replying.
well i think there is something wrong with it as after doing this step:
particle.velocity = particle.velocity - (dot(particle.velocity, rVector) / dot(rVector, rVector)) * rVector;
the velocity of of the particle becomes 0 in the y dimension and there is no other change.

it was a coding problem which basically involved physics and nothing else. So can be asked in both as different forums have people with different set of with expertise. But it suits more here than stackoverflow.

I am again asking it here as it is not coding which is causing the problem but the wrong formula to get the velocity component.

11. May 12, 2010

### diazona

Maybe that's what is supposed to happen....?

What numbers are you using for the particle velocity and the radius vector?

12. May 12, 2010

### khalsa

I changed this
Code (Text):
particle.velocity = particle.velocity - (dot(particle.velocity, rVector) / dot(rVector, rVector)) * rVector;
to

Code (Text):
particle.velocity = particle.velocity - (dot(particle.velocity ,rVector)/dot(rVector,rVector))*(rVector/dot(rVector,rVector))
And this seems to give acceptable result.

For a initial velocity vector say:
initial velocity = <-0.33, -1.41, 21>
using formula 1 after collision = <-0.33, 0, 21>
using formula 2 after collision =<-0.33, 11.28, 21>

Last edited: May 12, 2010
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook