Tuesday, December 21, 2010

UVA Problem#190


1. take x1, y1, x2, y2, x3 and y3 as input.
2. calculate m1 and m2. m1= (y2-y1)/(x2-x1); m2= (y3-y1)/(x3-x1);
3. for different condition (values) of m1 and m2 the formula to find h and k (circles center) will be different.
4. Formulas of h and k on different conditions
     (i) m2=0;  k=(x2-x3)/m1/2+(y1+y2)/2; h=(x1+x3)/2;
     (ii) m1=0; k=(x3-x2)/m2/2+(y1+y3)/2; h=(x1+x2)/2;
     (iii) m1!=0 and m2!=0; h=((x1+x2)/m1-(x1+x3)/m2+y2-y3)/2/(1/m1 - 1/m2); 
      k=( h-(x1+x2)/2)/(-m1)+(y1+y2)/2;
5. Find the radius 'r' from r= sqrt((h-x1)*(h-x1) + (k-y1)*(k-y1))
6. Find the center 'c' from c= ((r*r)-(h*h)-(k*k))
7. Find the sign from the following equations
        a=(h<0)?'+' : '-';
        b=(k<0)? '+' : '-';
        s=(c<0)? '+' : '-';
8. For different conditions of h and k now print the equations. 
    (i) k=0, h!=0; 
            printf("(x %1c %.3lf)^2 + y^2 = %.3lf^2\n", a, fabs(h), r);
            printf("x^2 + y^2 %1c %.3lfx %1c %.3lf = 0\n\n", a, fabs(2*h), s, fabs(c));
    (ii) h=0, k!=0;
            printf("x^2 + (y %1c %.3lf)^2 = %.3lf^2\n", b, fabs(k), r);
            printf("x^2 + y^2 %1c %.3lfy %1c %.3lf = 0\n\n", b, fabs(2*k), s, fabs(c));
    (iii) h1=0, k!=0;
            printf("(x %1c %.3lf)^2 + (y %1c %.3lf)^2 = %.3lf^2\n", a, fabs(h), b, fabs(k), r);
            printf("x^2 + y^2 %1c %.3lfx %1c %.3lfy %1c %.3lf = 0\n\n", a, fabs(2*h), b, fabs(2*k), s, fabs(c));

No comments:

Post a Comment