Sign in to follow this  
Wolvorine

calculating 2d Circle collesion

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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this