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

**URL:** <https://discourse.processing.org/t/bouncing-of-an-immovable-large-circle-a-moving-small-circle-and-a-gravity-and-right-force-vector/19443>\
**Category:** Coding Questions\
**Created:** [April 5, 2020, 6:19pm UTC](https://discourse.processing.org/t/bouncing-of-an-immovable-large-circle-a-moving-small-circle-and-a-gravity-and-right-force-vector/19443 "2020-04-05T18:19:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![worm888](https://avatars.discourse-cdn.com/v4/letter/w/a183cd/32.png) [@worm888](https://discourse.processing.org/u/worm888)\
**Post date:** [April 5, 2020, 6:19pm UTC](https://discourse.processing.org/t/bouncing-of-an-immovable-large-circle-a-moving-small-circle-and-a-gravity-and-right-force-vector/19443/1 "2020-04-05T18:19:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![worm888](https://avatars.discourse-cdn.com/v4/letter/w/a183cd/32.png) [@worm888](https://discourse.processing.org/u/worm888)\
**Post date:** [April 5, 2020, 6:22pm UTC](https://discourse.processing.org/t/bouncing-of-an-immovable-large-circle-a-moving-small-circle-and-a-gravity-and-right-force-vector/19443/2 "2020-04-05T18:22:32Z")

</div>

Sorry, I formatted the code wrong

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [April 18, 2020, 9:26pm UTC](https://discourse.processing.org/t/bouncing-of-an-immovable-large-circle-a-moving-small-circle-and-a-gravity-and-right-force-vector/19443/5 "2020-04-18T21:26:16Z")

</div>

Consider checking out these examples:

[https://processing.org/examples/bouncybubbles.html](https://processing.org/examples/bouncybubbles.html)  
[https://processing.org/examples/bouncingball.html](https://processing.org/examples/bouncingball.html)

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.
