Jump to content
  • Advertisement
Sign in to follow this  
Wolvorine

calculating 2d Circle collesion

This topic is 4122 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi, I am creating a game i dont know how could i achieve the below targets. Overview: There is one big circle exist in the middle of the screen, that circle needs to be covered by 5 small circles. If all small circle accurately cover the whole BIG circle and doesnt let any part naked then user will get high score. If he couldnt cover the whole BIG circle with small circles then player will get low score. Problem: 1)I dont know by which method i can calculate that how much part of the BIG circle is still visible. 2) I need to do 2d graphic techniew to calculate the areas of all circles. 3) Any formula or site for this kind of information??? please kindly guide me what to do?? Regards

Share this post


Link to post
Share on other sites
Advertisement
Well the task is to get the amount of pixels that the small circles are overlapping the larger circle.

So you first need to calculate how many pixels are in the big circle. This will give you a target for the amount of pixels that are possible to overlap.

Then you can modify some pixel perfect collision detection code and count the number of pixels that the small circles overlap with the larger circle.

Then you also need to take into account overlap between two small circles and exclude that from your final calculation.

To do that you would need to keep track of which overlaps have already been found so that you don't count the overlaps twice. Either that or you could only subtract half the amount that needs to be subtracted and just assume that the overlap will be detected twice.

Share this post


Link to post
Share on other sites
dx = circle1.x - circle2.x;
dy = circle1.y - circle2.y;
dist_squared = dx * dx + dy * dy;
radius_sum = circle1.radius + circle2.radius;
if (dist_squared < (radius_sum * radius_sum))
collision();
else
no_collision();

The above is for collision between two circles, to make sure the smaller circles are in the bigger circle (if I understand you correctly). You can modify the above to make sure the entire circle is contained in another circle, if you wish.

Then, it's a matter of calculating the area of each of the circles and substracting.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!