Advertisement
Guest User

A complex cone

a guest
Apr 3rd, 2020
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.85 KB | None | 0 0
  1. #include<iostream>
  2. #include<cmath>
  3.  
  4. int main()
  5. {
  6.     int t;
  7.     scanf("%d", &t);
  8.    
  9.     while(t--)
  10.     {
  11.         int r, h, a, b;
  12.         scanf("%d%d%d%d", &r, &h, &a, &b);
  13.         double delta = 1e-5;
  14.         double area = 0.0;
  15.         double y = 0.0;
  16.         double volumeIntersect = 0.0;
  17.         do
  18.         {
  19.             double c = (y * (a+b)) /(2*r*(h-y));
  20.             double d = (r - r * y / h);
  21.             double e = 2 * std::acos(c) * d * d;
  22.             double f = y * (a+b) / (2*h);
  23.             double g = std::sqrt(d * d - f * f) * y * (a+b) / h;
  24.             area = (e - g);
  25.             volumeIntersect += area * delta;
  26.             y += delta;  
  27.         } while (area - delta > 0);
  28.         double volume = 2.0 * h * r * r * M_PI / 3.0;
  29.        
  30.         printf("%f\n",volume - volumeIntersect);
  31.     }
  32.    
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement