For my game I need to have a circle collide against a wall and bounce off in the appropriate direction. I've looked around for a while and haven't found a good solution to my problem. I have a diagram of what should happen below.
The problem is that I have the vector V, U, and P, but I am unable to calculate the new X and Y vectors after the collision. I have tried using Trig to find the angle of the intersection and get the new X and Y vectors from that but it gives massive numbers. How do I get the new X and Y vectors easily? Source code is posted below.
for (int i = 0; i < collisionList.size(); i++){
Vec2<Integer> c = collisionList.get(i);
int cx = c.getX();
int cy = c.getY();
if (distance(x, y, cx, cy) <= (r - (r / 2))){
float mag = (float)Math.sqrt((Math.pow(x, 2) + Math.pow(y, 2)));
float angleRad = (float)Math.atan(y / x);
xVel = (float)(mag * Math.cos(angleRad));
yVel = (float)(mag * Math.sin(angleRad));
}
}