Click here to Skip to main content
15,903,388 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
A collision occurs when two objects overlap. That is to say they both occupy the same space, either in whole or in part. As this shall be our first collision exercise, we shall limit our efforts to detecting collisions between pairs of circles.
You shall repeat the process of creating circle pairs, detecting their collision status, and displaying them in the GDIDrawer window each time the user presses the spacebar. If the user presses any other key, even before the first pair is evaluated, your program shall exit.
In order to create pairs of circles you will require two sets of information. Each circle will require a radius and a center point described by an X- and Y-coordinate pair. These values shall be generated randomly, adhering to the following rules:
1) Each radius shall have a size between 25 and 200 inclusive.
2) The location of the circles shall be set such that the entirety of each circle may be displayed within the GDIDrawer window. Remember that the GDIDrawer window is 800 x 600 pixels.
Once the values for describing the circles have been generated, you must create an equation which will allow you to determine whether the circles collide. To be clear, if your equation determines that the circles are either touching or overlapping, then they shall be considered to have collided.
Finally, if your equation determines that the circles have collided, you shall display both circles colored red in the GDIDrawer window as shown in Figure 11-1 at the top of the following page. On the other hand, if your equation determines that the circles have not collided, then you shall display them in the GDIDrawer window with randomized values for red, green, and blue as shown in Figure 11-2 at the bottom of the following page.
Figure 11-1: Sample Set of Circles Which Have Collided
Figure 11-2: Sample Set of Circles Which Have Not Collided
Updated 4-Mar-13 13:52pm
Jegan Thiyagesan 4-Mar-13 16:50pm    
Instead of posting your homework here, you should say, what are you trying to achieve, what have you tried, where did you got stuck? so that we can help you.

We are not here to do your home work.
joshrduncan2012 4-Mar-13 17:10pm    
Nice, +5.

Two circles collide is the distance between their centers becomes less or equal to the sum of their radii, isn't that obvious? This is trivial, and the calculation of the collision criterion based on this should be even more trivial. Any further questions?

Share this answer
Abhinav S 4-Mar-13 21:22pm    
5 indeed.
Sergey Alexandrovich Kryukov 4-Mar-13 22:19pm    
Thank you, Abhinav.
fjdiewornncalwe 4-Mar-13 21:50pm    
Sergey Alexandrovich Kryukov 4-Mar-13 22:19pm    
Thank you, Marcus.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900