Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# Homework
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 4-Mar-13 11:45am
Edited 4-Mar-13 14:52pm
v2
Comments
Jegan Thiyagesan at 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 at 4-Mar-13 17:10pm
   
Nice, +5.
Rate this: bad
good
Please Sign up or sign in to vote.

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
  Permalink  
Comments
Abhinav S at 4-Mar-13 21:22pm
   
5 indeed.
Sergey Alexandrovich Kryukov at 4-Mar-13 22:19pm
   
Thank you, Abhinav.
—SA
Marcus Kramer at 4-Mar-13 21:50pm
   
+5.
Sergey Alexandrovich Kryukov at 4-Mar-13 22:19pm
   
Thank you, Marcus.
—SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

  Permalink  

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

  Print Answers RSS
0 OriginalGriff 7,903
1 Sergey Alexandrovich Kryukov 7,192
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,820


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 4 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100