CMPT 102: Assignment #3

Due October 30, 2006


NOTE1: YOU MUST USE THE VARIABLE NAMES SPECIFIED IN THE ASSIGNMENT, failure to do so will result in deduction of points.
NOTE2: If you were unable to get the program in assignment 2 working you may (with a small penalty) use the solution code in assignment 2's solution as a starting point. If you choose to use the solution code there will be a 4 point deduction from the 100 points available for assignment 3.

PART 1: Function for finding the intersection of two circles.  (40 points)

Take your program for determining the intersection of two circles and convert the program into a function. The prototype for the function should be:

void CircIntersect(double XCentre1, double YCentre1, double Radius1, double XCentre2, double YCentre2, double Radius2, double *XIntersect1p, double *YIntersect1p, double *XIntersect2p, double *YIntersect2p, int *NumIntersectp);

In your function you will have five double variables, XIntersect1, YIntersect1, XIntersect2, YIntersect2, and NumIntersect. (XIntersect1, YIntersect1) is the (x,y) location of the first intersection point if there is one. (XIntersect2, YIntersect2) is the (x,y) location of the second intersection point if there is one. NumIntersect is the number of intersection points between the pair of circles. In your CircIntersect function, after determining the number and location of the intersections, instead of printing the messages indicating the number of intersections and the locations of the intersection points, add the following statements used to pass the values of your results back to main program.
In all cases add
*NumIntersectionp = NumIntersection;
If there are one or more points of intersecton also add
*XIntersect1p = XIntersect1;
*YIntersect1p = YIntersect1;
If there are two points of intersection also add
*XIntersect2p = XIntersect2;
*YIntersect2p = YIntersect2;

Write a main program to test your CircIntersect function. Remember that input and output should be done outside of your function. When you are sure your CircIntersect function is working you are ready to begin implementation of the detailed algorithm you have developed to solve the problem in PART 2. If your circle intersection program is not reliable you may use the program provided as a solution to problem 1.  Using the solution rather than your own program will result is a penalty of 4 points.

PART 2: Finding the location of an Earthquake (60 points)

While developing your program follow the software development method, you will need to submit each of the following as part of your solution:

How can we locate an Earthquake? A simple geometric method of locating an earthquake on the surface of the Earth can be outlined as follows:

Your problem is to translate this algorithm into a computer program. This inputs to this program will be the (x,y) locations of the three recording stations and the distances from each of the recording stations to the earthquake.
You will use your CircIntersect function in your earthquake location program. In the development of the earthquake location program, you may call this functions without providing the detailed algorithm or flowchart for what happens inside the functions.
A summary algorithm for approaching the translation of the algorithm above into a computer algorithm is given below: