Difficulty having two balls bounce against eachother without clipping

planangle = new PVector(location.x-plan.location.x, location.y-plan.location.y);
// if (-90<velocity.heading() && velocity.heading()<90) {
// planangle.rotate(PI);
//}
if (dist(location.x, location.y, plan.location.x, plan.location.y)<plan.r+r+8) {
location = new PVector(cos(location.heading()) *(location.mag()), sin(location.heading())* (location.mag()));
println("heading ", velocity.heading(),planangle.heading());
println("velocity ", velocity);
println("planangle ", planangle);
if(velocity.heading() > 0 && velocity.heading()<radians(90)){
velocity.rotate(PI);
velocity.rotate(2 <em>PVector.angleBetween( planangle,velocity)).mult(0.95);
}
if(velocity.heading() >= 90 && velocity.heading()<radians(180)){
velocity.rotate(PI);
velocity.rotate(-2</em> PVector.angleBetween( planangle,velocity)).mult(0.95);
}
println("alpha angle ",PVector.angleBetween(planangle,velocity));
}

I’m making a project with forces for a class, and I’m trying to get a smaller circle to bounce off the larger circle kind of how it would act like in gravity. I have a vector that pulls the smaller circle in. It works mostly, but every 3-5 bounces it just clips through the large circle and falls down it, and then resumes working normally. Help!
Also, it often happens after it bounces off the right wall, and it seems that going left means that it just clips through the thing.

Please either:

  1. Post the entire sketch
  2. Post the folder as a *.zip file then link to it here.

The code is unreadable out of context. (at least for me)