15,903,388 members
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
Posted
Updated 4-Mar-13 13:52pm
v2
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.

## Solution 1

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?

—SA

Abhinav S 4-Mar-13 21:22pm
5 indeed.
Sergey Alexandrovich Kryukov 4-Mar-13 22:19pm
Thank you, Abhinav.
—SA
fjdiewornncalwe 4-Mar-13 21:50pm
+5.
Sergey Alexandrovich Kryukov 4-Mar-13 22:19pm
Thank you, Marcus.
—SA

## Solution 2

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

Top Experts
Last 24hrsThis month
 Richard Deeming 85 OriginalGriff 45 Kevin Marois 20 Dave Kreskowiak 20 CPallini 20
 Pete O'Hanlon 1,580 OriginalGriff 1,227 Richard Deeming 445 Richard MacCutchan 355 Dave Kreskowiak 340

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