Tuesday, November 10, 2015

UVa 12901 - Refraction

#include <math.h>
#include <stdio.h>
int main(){
    int t;
    double i, r, A, pi;
    double W,  H, h, w, x1, x2, y2, u;
    double m1, m2, c1, c2;
    //freopen ("in.txt", "r", stdin);
    scanf ("%d\n", &t);
    pi = 3.14159265358;
    while(scanf("%lf  %lf  %lf  %lf  %lf  %lf\n", &W, &H, &x1, &x2, &y2, &u) == 6){
 
    if(x2 - W != 0)
       m1 = (y2 - H) / (x2 - W);
if(x2-W != 0)
       c1 = (-x2*H + W*y2) / (W - x2);
i = (pi/2) - atan(m1);
r = asin(sin (i)/u);
A = (pi/2) - r;
m2 = tan (A);
c2 = -x1*m2;

if(m1-m2 != 0)
        w = (c2 - c1) / (m1 - m2);
        h = m1*w + c1;

if (h > H)
        printf ("Impossible\n");
   else
        printf ("%.4lf\n", h);
   }
   return 0;
}