If Statements and Circles

Given the user input of 6 doubles
• an x value, a y value (for a center point) and a radius value for a circle and
• an x value, a y value (for a center point) and a radius value for a second circle
Your program should output whether the circles intersect and, if they do, how they intersect. Here are the 10 cases or categories that can occur:
1. ...do not intersect.





2. ...just touch from the outside.






3. ...intersect with the centers outside of each other.





4. ...intersect with one circle's center inside the other.






5. ... do not intersect but one circle contains the other.






6. ... are the same circle.





7. ... just touch from the inside.





8. ...intersect with one circle's center on the other circle.






9. ... are concentric circles.





10. ...are the same size with each circle's center on the other circle.






Your program must print one of the following (like the numbered labels above):
1. These 2 circles do not intersect.
2. These 2 circles just touch from the outside.
3. These 2 circles intersect with the centers outside of each other.
4. These 2 circles intersect with one circle's center inside the other.
5. These 2 circles do not intersect but one circle contains the other.
6. These 2 circles are the same circle.
7. These 2 circles just touch from the inside.
8. These 2 circles intersect with one circle's center on the other circle.
9. These 2 circles are concentric circles.
10. These 2 circles are the same size with each circle's center on the other circle.
Please note that there is more than one solution to this problem. The order of your if statements can be really important, and you might consider "cherry picking" the easiest case(s) to solve first. You should also test each new if statement individually (i.e. write one if statement  run your code  make sure it works as intended  comment out that if statement  repeat).
NOTE: You MUST comment each if statement explaining what your expression is trying to determine. Your comments MUST be more detailed that in previous assignments.
//doing math is not acceptable for this assignment. Your comments should be something like: //this expression determines if the two circles are the same
________________________________________
Sample Output: Your program will be tested with several input sets, including the one shown here in RED. Your program must exactly match the words and format in this example. (Please copy and paste the text from these prompts into your code! You are graded on this on Web-CAT.) The output varies, of course, based on the input numbers.
________________________________________
Please enter the X, Y coordinates of Circle 1: 0 0
Please enter the radius of Circle 1: 2
Please enter the X, Y coordinates of Circle 2: 0 4
Please enter the radius of Circle 2: 2

These 2 circles just touch from the outside.


Please, run your code with several different inputs and hand check the values to make sure your code is doing the calculations right. You can use WolframAlpha to make up test data: http://www.wolframalpha.com/input/?i=circle+at+%280%2C0%29+with+radius+%3D+2+AND+circle+at+%280%2C2%29+with+radius+%3D+2.
Solution Approach
To start, most of these if statement conditions only compare radii of the circles and the distance between the circles' centers!!! Think of it like this example... I always like to color code.






For example, the purple Circle1 has a radius called r1 and an X, Y position of the center called x1 and y1. The red Circle2 has a radius called r2 and an X, Y position of the center called x2 and y2. The distance between Circle1 center and Circle2 center is sqrt( (x1 - x2)2 + (y1 - y2)2 ). The pink line is this distance.
If pink line (distance) is greater than [red line (r2) + purple line (r1)], then you print "These 2 circles do not intersect."
If they are equal to, then they "touch."
If they are less than, then they are in the other 86 categories, for which you have to test additional conditions. This is the problem-solving aspect of programming. It is up to you to come up with how to determine the remaining 86 categories.
It is strongly recommended that you begin this assignment on paper. You should be able to work though the logic of the problem before you begin to code.
NOTE: You should use the fabs() operator to compare equality between doubles on this assignment. ex:
//this expression determines if the two circles just touch from the outside
if ( fabs(r1 + r2 – distance) < .0001)
{
cout << “These 2 circles just touch from the outside.”;
}
We will talk through all of the cases in class, so you really should attend lecture!

How to start the program
1. Create a new project & start with the honor code, #includes, and main (don’t forget the doxygen / javadoc comment) You need the math library for this one again.
2. Write the cout and cin statements to prompt and read the input.
3. Write 1 if statement that checks for the first condition ( d > r1 + r2 ) and prints the proper output. [copy and paste the output please!] Have an else for the if that prints “Error!”
4. TEST IT with several different inputs, like 2, 2 radius 1 AND 6, 3 radius 3. That's 1 test!
5. Add an else if statement that tests for the 'touch' condition.
6. TEST IT with several different inputs.
7. You do NOT have to solve these in order #1, #2, #3, etc.
8. Write another easy one, like #6 or #9.
9. What are examples of each of the categories???
10. Add another else if statement for another one of the categories.
11. TEST IT with more input data.
12. Repeat until you have covered all of the possible circle relationships (10 total).
Hi,

this is not a homework site... please post what you did/tried
Can you send me a private message?
Topic archived. No new replies allowed.