Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8688751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:27:20+00:00 2026-06-12T23:27:20+00:00

I have a big Circle and about 30 small bubbles which are inside the

  • 0

I have a big Circle and about 30 small bubbles which are inside the big one. The small bubbles can not go out of the big Circle, and when on of the small bubbles meets another they deflect to the opposite direction.

This is the code for the deflection of two small circles:

var xVelocityBubble1 = Math.random();
var yVelocityBubble1 = Math.random();

var xVelocityBubble2 = Math.random();
var yVelocityBubble2 = Math.random();

moveBubbles = function() {
xbubble1 += xVelocityBubble1;
ybubble1 += yVelocityBubble1;

xbubble2 -= xVelocityBubble2;
xbubble2 -= yVelocityBubble2;

if (Math.sqrt(Math.pow(xbubble1 - xbubble2, 2) + Math.pow(ybubble1 - ybubble2, 2)) < radius * 2) {
xVelocityBubble1 *= -1;
yVelocityBubble1 *= -1;
xVelocityBubble2 *= -1;
yVelocityBubble2 *= -1;
}
}

Bubbles inside a big Circle

Now, here is the problem. As you can see on this picture, sometimes my bubbles are colliding, and I do not know why. Everything works fine until one circle gets crashed, then suddenly more and more bubbles are in a war. Have a look at circles 375, 240,330 and 410. First I thought this might has something to do with the different velocities, but that was not the problem. Has anyone any idea?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T23:27:23+00:00Added an answer on June 12, 2026 at 11:27 pm

    Your code assumes that the circles collide because they are moving straight towards each other, and therefore the reaction of the collision would be that both circles go in the exact opposite direction instead.

    For circles meeting that are moving in almost the same direction, that reaction will be strange. You should calculate the angle where the circles meet, and from that calculate how much momentum they exchange and how that affects each circle.

    It’s probably because of that erratic reaction combined with circles doing more than one collision in one round of calculations that makes them move into each other. As a circle make a 180 degree turn for any collision, that means that if it collides two times (or any even number) it will just continue going as if nothing happened.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have big dataset (but the following is small one for example). I can
I have a small circle which is inside a bigger circle. The small Circle
I have a tikz picture with a circle node which has a number inside.
I have a big VS2010 solution, which contains a bunch of C# projects. One
I have big URL list, which I have to download in parallel and check
I have big problems with stopping a service, which plays audio file. I want
I'm new to Jira and have big problem with creating tables inside my testing
I have a small webshop-like web application, and i have big plans :-) I
I have big collection of tweets stored in MongoDB. Tweets look like this one:
circle player - brilliant, stylish. circle player - too big. I have successfully scaled

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.