Bouncing of an immovable large circle, a moving small circle and a gravity and right force vector

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(2*PVector.angleBetween( planangle,velocity)).mult(0.95);
      if(velocity.heading() >= 90 && velocity.heading()<radians(180)){
        velocity.rotate(-2*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!

1 Like

Sorry, I formatted the code wrong

Consider checking out these examples:

At extreme speeds, clipping through will always be possible if your only check is circle-circle collision. if you keep previous and next coordinate for the ball, that can form a line, and you can do line-circle collision on the path as additional check to avoid flying through obstacles.