# Calculate velocity of a bullet ricocheting on a circle

I made a picture to demostrate what I need,basecaly I have a bullet with velocity and I want it to bounce with the correct angle after it hits a circle

Solved(look the accepted answer for explain):

``````Vector.vector.set(bullet.vel);    //->v
Vector.vector2.setDirection(pos, bullet.pos);     //->n normal from center of circle to bullet
float dot=Vector.vector.dot(Vector.vector2);    //->dot product
Vector.vector2.mul(dot).mul(2);
Vector.vector.sub(Vector.vector2);
Vector.vector.y=-Vector.vector.y;  //->for some reason i had to invert the y
Vector.vector.normalize();
bullet.vel.set(Vector.vector);
``````

-
Do you need direction or velocity? If direction that is elementary school stuff... and you are already doing it in almost any shading model. – wondra Aug 17 '14 at 19:21
@wondra just the direction.Well many years have passed since elementary :) – SteveL Aug 17 '14 at 19:29
Find the slope of the circle at the point of intersection (the derivative). Use that slope/line as the line of reflection for the incoming bullet. – Byte56 Aug 17 '14 at 21:31
Some explain for the downvotes ? – SteveL Aug 18 '14 at 10:11

The formula for reflecting an incoming vector `v` across a unit normal `n` into an outgoing vector `v'` is
``````v' = v - 2*dot(v,n)*n
You can determine the normal `n` from normalizing the difference of the collision point and the center of the circle.