The Story of Two Coins

In this problem we have two coins (perfect circles) in a two dimensional world. The radius of first coin is R and the radius of the second coin is r. The first coin is static and the location of its center Q is at the origin (0,0). The second coin (with radius r) is rotating in counter clock-wise direction like a wheel on the perimeter of the first circle, as shown in the picture below. As it is rotating counter clock wise so it is also moving along the surface of the first circle in counter clock-wise direction. After the second coin has rotated exactly once around the first coin, it stops. At the beginning, the center of the second coin (Denoted by O in the figure above) is on the x-axis and on the right hand side of the first coin. So initially the coordinate of O is (R+r,0). At this moment P is the topmost point of the second coin. So obviously the coordinate of P is (R + r, r). Now as the second coin starts rotating the location of P will change due to both circular translation and its own rotation. For most positions of the second coin, P will not be its topmost point. T is any arbitrary point on the perimeter of the moving second coin. If the Cartesian coordinate of T, (x,y) is given, then it is possible to determine the position of the second coin. Of course there can be two possible positions as shown in the figure above. Now your job is a little bit difficult than this. Given the coordinate of T, you will have to find the coordinate of P for two possible positions of the second coin. Input The input file contains at most 1000 lines of inputs. Each line contains two positive integers and two floating-point numbers. The two positive integers are R, r (0 < |r| ≤ |R| < 1000) and the two floating point numbers are x and y (0 < |x|,|y| < 4000.0). The meanings of these symbols are given in the

2/2 problem statement above. All the floating-point numbers in the input will have fifteen digits after the decimal point. Input is terminated by a line where the values of R and r are zero. Your program should not process this line. Output For each line of input produce three or two lines of output. The first line contains the serial of output. The next two lines contain the possible coordinates of P for two possible positions of the second coin. The coordinates of P should be printed in chronological order (If a position is reached by the second coin before the other position then the corresponding coordinates of P should be printed first). If it is not possible to find the coordinate of P for the given data, print ‘IMPOSSIBLE’ instead. There will be no such input that will cause the second coin to have exactly one possible position. Also note that there will be no such input, which will allow precision error to cause difference in the output. Assume that π = 2 cos−1(0), and use at least double precision (64-bit) floating-point numbers for your calculations. All floating-point numbers should be rounded to three digits after the decimal point. Look at the output for sample input for details. Sample Input 5 5 10.000000000000000 3.000000000000000 5 5 20.000000000000000 10.000000000000000 0 0 0.000000000000000 0.000000000000000 Sample Output Case 1: 2.082 7.076 11.755 2.606 Case 2: IMPOSSIBLE