Advertisement
saske_7

uva_190.cppl(working with line )

Nov 14th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.09 KB | None | 0 0
  1.  
  2. #include<bits/stdc++.h>
  3. using namespace std ;
  4.  
  5. #define M 999999999999999999
  6. #define pii pair<int , int >
  7. #define mp make_pair
  8. #define pf printf
  9. #define sf scanf
  10. #define sf1(a ) scanf("%d",&a)
  11. #define pb push_back
  12. #define sf2(a, b) scanf("%d%d",&a ,&b)
  13. #define rep(i,n ) for(i = 0 ; i< n ;i++ )
  14.  
  15. typedef long long LL ;
  16. LL num ;
  17.  
  18. struct  _line{
  19. double a  , b ,c , m  , mid_x, mid_y ;
  20.  
  21. };
  22.  
  23. struct _point
  24. {
  25.   double x , y;
  26. };
  27.  
  28. vector<_line> line ;
  29. vector<_point> point ;
  30. double p_1 , p_2;
  31.  
  32. void call(_point p1 , _point p2); // makes line eqn from 2 points
  33. void make_line(_line p1   );
  34. int i_sec(_line p1 , _line p2);
  35.  
  36. void print(double rad){
  37. double c ;
  38. c =  p_1*p_1 +p_2*p_2 - rad*rad ;
  39.  
  40.   /*if(p_1 == 0 && p_2 == 0){
  41.       pf("x^2 + y^2 = %.3lf^2\n",rad );
  42.     if(c < 0)
  43.     pf("x^2 + y^2 - %.3lf = 0\n",p_1*2 , p_2*2,-c );
  44.     else
  45.         pf("x^2 + y^2 + %.3lf = 0\n",p_1*2 , p_2*2,c );
  46.     return ;
  47.   }
  48.   else if(p_1 ==  0){
  49.      pf("x^2 + (y - %.3lf)^2 = %.3lf^2\n", p_2 ,rad );
  50.     if(c < 0)
  51.     pf("x^2 + y^2 - %.3lfy - %.3lf = 0\n" , p_2*2,-c );
  52.     else
  53.         pf("x^2 + y^2 - %.3lfy + %.3lf = 0\n", p_2*2,c );
  54.  }
  55.   else if(p_2 == 0)
  56.   {
  57.     pf("(x - %.3lf)^2 + y^2 = %.3lf^2\n",p_1 ,rad );
  58.     if(c < 0)
  59.     pf("x^2 + y^2 - %.3lfx - %.3lf = 0\n",p_1*2 ,-c );
  60.     else
  61.         pf("x^2 + y^2 - %.3lfx + %.3lf = 0\n",p_1*2 ,c );
  62.  
  63.  
  64.   }*/
  65.  
  66.    if(p_1 > 0 && p_2 > 0){
  67.     pf("(x - %.3lf)^2 + (y - %.3lf)^2 = %.3lf^2\n",p_1 , p_2 ,rad );
  68.     if(c < 0)
  69.     pf("x^2 + y^2 - %.3lfx - %.3lfy - %.3lf = 0\n",p_1*2 , p_2*2,-c );
  70.     else
  71.         pf("x^2 + y^2 - %.3lfx - %.3lfy + %.3lf = 0\n",p_1*2 , p_2*2,c );
  72.  
  73.   }
  74.   else if(p_1 < 0  && p_2< 0){
  75.      pf("(x + %.3lf)^2 + (y + %.3lf)^2 = %.3lf^2\n",-p_1 , -p_2 ,rad );
  76.      if(c >= 0)
  77.      pf("x^2 + y^2 + %.3lfx + %.3lfy + %.3lf = 0\n",-p_1*2 , -p_2*2,c );
  78.    else
  79.       pf("x^2 + y^2 + %.3lfx + %.3lfy - %.3lf = 0\n",-p_1*2 , -p_2*2,-c );
  80.  
  81.  
  82.   }
  83.   else if(p_1 < 0 && p_2 > 0){
  84.  
  85.     pf("(x + %.3lf)^2 + (y - %.3lf)^2 = %.3lf^2\n",-p_1 , p_2 ,rad );
  86.      if(c >= 0)
  87.         pf("x^2 + y^2 + %.3lfx - %.3lfy + %.3lf = 0\n",-p_1*2 , p_2*2,c );
  88.      else
  89.         pf("x^2 + y^2 + %.3lfx - %.3lfy - %.3lf = 0\n",-p_1*2 , p_2*2,-c);
  90.  
  91.  
  92.   }
  93.   else if(p_1 >0 && p_2 <0){
  94.  
  95.     pf("(x - %.3lf)^2 + (y + %.3lf)^2 = %.3lf^2\n",p_1 , -p_2 ,rad );
  96.      if(c >= 0)
  97.         pf("x^2 + y^2 - %.3lfx + %.3lfy + %.3lf = 0\n",p_1*2 , -p_2*2,c );
  98.      else
  99.         pf("x^2 + y^2 - %.3lfx + %.3lfy - %.3lf = 0\n",p_1*2 , -p_2*2,-c );
  100.  
  101.  
  102.  
  103.   }
  104.  
  105.   return ;
  106. }
  107.  
  108.  
  109. int main(){
  110. freopen("in.txt","r",stdin );
  111. freopen("out.txt","w",stdout );
  112.  
  113.  
  114. double x1 , y1 ;
  115. int i , j ,k ;
  116. while(  scanf("%lf %lf",&x1 , &y1)==2 ){
  117.   point.clear();
  118.   line.clear();
  119. _point pvar;
  120.  
  121.   pvar.x = x1;
  122.   pvar.y = y1 ;
  123.   point.push_back(pvar);
  124.  
  125.   for(i = 2;i<= 3 ; i++){
  126.     scanf("%lf %lf",&x1 , &y1);
  127.     pvar.x = x1;
  128.     pvar.y = y1 ;
  129.     point.push_back(pvar);
  130.   }
  131.  
  132.   call(point[0]  , point[1]);
  133.   call(point[1]  , point[2]);
  134.   call(point[2]  , point[0]);
  135.  
  136.    /* for(i = 0  ;i< 3 ;i++)
  137.     {
  138.         _line v ;
  139.         v  = line[i];
  140.       //  pf("line %d  : %lf %lf %lf %lf %lf %lf\n",i ,v.a , v.b , v.c , v.m ,v.mid_x , v.mid_y);
  141.  
  142.  
  143.     }
  144. */
  145.   make_line(line[0] );
  146.   make_line(line[1] );
  147.   make_line(line[2] );
  148. //pf("printing derived line\n");
  149.   //  for(i = 3  ;i< 6 ;i++)
  150.     //{
  151.      //   _line v ;
  152.        // v  = line[i];
  153.    //     pf("line %d  : %lf %lf %lf %lf %lf %lf\n",i ,v.a , v.b , v.c , v.m ,v.mid_x , v.mid_y);
  154.  
  155.  
  156.    // }
  157.   i_sec(line[3] ,line[4]);
  158.  // pf("intersecting %lf %lf\n",p_1 , p_2 );
  159. double rad ;
  160.   rad  = sqrt((p_1 - point[0].x)*(p_1 - point[0].x) + (p_2 - point[0].y)*(p_2 - point[0].y));
  161. //  pf("intersecting %lf %lf %lf\n",p_1 , p_2, rad );
  162.   print(rad);
  163.  
  164.   pf("\n");
  165.  
  166.  
  167. }
  168.  
  169.   return 0 ;
  170. }
  171.  
  172.  
  173.  
  174.  
  175. void call(_point p1, _point p2 ){
  176. double x1 ,y1 ,x2, y2 ;
  177.   x1  = p1.x;
  178.   x2 =  p2.x;
  179.  
  180.   y1 =  p1.y;
  181.   y2 =  p2.y;
  182.  _line var ;
  183.  
  184.  var.mid_x =( x1 + x2)/2  ;
  185.  var.mid_y = (y1 + y2)/2 ;
  186.  
  187. if(y1 ==  y2){
  188.   var.a = 0;
  189.   var.b = 1;
  190.   var.c = -y1;
  191.   var.m = 0;
  192.  line.push_back(var);
  193.  
  194.   return ;
  195. }
  196.  
  197. else if(x1 == x2 ){
  198.   var.a = 1;
  199.   var.b = 0;
  200.   var.c = -x1;
  201.   var.m = 0;
  202.  line.push_back(var);
  203.   return ;
  204. }
  205. else {
  206.  
  207. double ret ;
  208.   ret =(double) (y2 - y1)/(x2 -  x1);
  209.   var.a = ret ;
  210.   var.b = -1;
  211.   var.c = -ret*x1  +y1;
  212.  var.m = ret ;
  213.  line.push_back(var);
  214.  
  215. return ;
  216.  
  217.   }
  218. }
  219.  
  220.  
  221. void make_line(_line p1){
  222.  
  223. _line var ;
  224. double slope , x1, y1 ;
  225.   slope = var.m = -1/p1.m;
  226.  if(p1.m == 0) slope = 0;
  227.   x1 = p1.mid_x;
  228.   y1 = p1.mid_y;
  229.  
  230.   var.a =  -slope ;
  231.   var.b = 1;
  232.   var.c =  -y1 + slope*x1;
  233.  
  234. line.push_back(var);
  235.  
  236. return ;
  237. }
  238.  
  239. int i_sec(_line p1 , _line p2){
  240.  
  241. double ret , ret1, ret2 , x1 ,y1 ,x2 ,y2;
  242. double px1, px2 , py1 ,py2;
  243.  
  244.  
  245. double a1, b1 ,c1 , a2 ,b2 ,c2 ;
  246.   a1 = p1.a ;
  247.   b1 = p1.b ;
  248.   c1 = p1.c ;
  249.  
  250.   a2 = p2.a ;
  251.   b2 = p2.b ;
  252.   c2 = p2.c ;
  253.  
  254. double hold ,k1 ,k2;
  255.   hold = a1*b2 - a2*b1 ;
  256.  if(hold == 0 ) cout << "trrrrr\n";
  257.   k1 = (double) (b1*c2 - b2*c1)/hold ;
  258.   k2 = (double)(c1*a2 - c2*a1)/hold ;
  259.  
  260.   p_1  = k1 ;
  261.   p_2 =  k2 ;
  262.  
  263.  
  264. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement