SHARE
TWEET

squares

frustration Feb 15th, 2020 (edited) 88 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <conio.h>
  2. #include <iostream>
  3. #include <cmath>
  4. #include <vector>
  5. #include <fstream>
  6. #include <stdio.h>
  7.  
  8. using namespace std;
  9.  
  10.  
  11. void cylindrical(double r, double alpha) {               //r-layers, alpha-polar angle, h- cylindrical's height(radius)
  12.     double delta_h = 1;
  13.     double sum = 0, sum1 = 0;
  14.  
  15.     vector <double> square_front(r + 1, 0);
  16.     vector <double> square_side(r + 1, 0);
  17.     vector <double> square_up(r + 1, 0);
  18.     vector <double> volume(r + 1, 0);
  19.  
  20.     for (int i = 0; i < r + 1; ++i)
  21.         square_front[i] = 0.5*alpha*((i + 1)*(i + 1) - i * i);
  22.  
  23.     for (int i = 0; i < r; ++i)
  24.         square_side[i] = delta_h * ((i + 1)*(i + 1) - i * i);
  25.  
  26.     for (int i = 0; i < r + 1; ++i)
  27.         square_up[i] = delta_h * (i + 1)*alpha;
  28.  
  29.     for (int i = 0; i < r; ++i)
  30.         volume[i] = 0.5*alpha*((i + 1)*(i + 1) - i * i)*delta_h;
  31.  
  32.  
  33.  
  34.     cout << " square_front-";
  35.     for (int i = 0; i < r; ++i) {
  36.         cout << square_front[i] << " ";
  37.         sum1 += square_front[i];
  38.     }cout << endl;
  39.  
  40.     cout << " square_side-";
  41.     for (int i = 0; i < r; ++i) {
  42.         cout << square_side[i] << " ";
  43.     }cout << endl;
  44.     cout << " square_up-";
  45.     for (int i = 0; i < r; ++i) {
  46.         cout << square_up[i] << " ";
  47.     }cout << endl;
  48.  
  49.     cout << " volume-";
  50.     for (int i = 0; i < r; ++i) {
  51.         cout << volume[i] << " ";
  52.         sum += volume[i];
  53.     }cout << endl;
  54.  
  55.  
  56.  
  57.  
  58.  
  59.     cout << endl << "all square " << 2 * 3.14* r*(1 + r) << " " << (square_up[r - 1] + sum1 * 2) * 18;
  60.     cout << endl << "all volume" << 3.14*r*r << " " << sum * 18<<endl;
  61. }
  62.  
  63.  
  64. void torus(double R, double r, double sectors) {
  65.     double alpha = 180 / sectors;
  66.     double sum1 = 0;
  67.     double delta_alpha = 3.14*alpha / 180;
  68.     cout <<"delta alpha "<< delta_alpha << endl;
  69.     vector < vector < double > > square_up(r + 1, vector<double>(sectors + 1, 0));
  70.     vector < vector < double > > square_right(r + 1, vector<double>(sectors + 1, 0));
  71.     vector < vector < double > > square_left(r + 1, vector<double>(sectors + 1, 0));
  72.     vector < vector < double > > square_front(r + 1, vector<double>(sectors + 1, 0));
  73.     vector < vector < double > > volume(r + 1, vector<double>(sectors + 1, 0));
  74.  
  75.     for (int i = 0; i < r; i++)
  76.         for (int j = 0; j < sectors; j++) {
  77.             square_up[i][j] = i * delta_alpha * 2 * 3.14*(R + i * cos((j + (j + 1)) / 2));
  78.         }
  79.  
  80.     for (int i = 0; i < r + 1; i++)
  81.         for (int j = 0; j < sectors; j++) {
  82.             square_left[i][j] = ((i + 1) - i) * 2 * 3.14*(R + (i + (i - 1)) / 2 * cos(j));
  83.         }
  84.  
  85.     for (int i = 0; i < r; i++)
  86.         for (int j = 0; j < sectors; j++) {
  87.             square_right[i][j] = (i - (i - 1)) * 2 * 3.14*(R + (i + (i - 1)) / 2 * cos(j + 1));
  88.         }
  89.  
  90.     for (int i = 0; i < r; i++)
  91.         for (int j = 0; j < sectors; j++) {
  92.             square_front[i][j] = delta_alpha * ((i + 1) - i)*(R + ((i + 1) - i) / 2 * cos(j + j + 1));
  93.         }
  94.  
  95.     for (int i = 0; i < r; i++)
  96.         for (int j = 0; j < sectors; j++) {
  97.             volume[i][j] = square_front[i][j] * 3.14 * 2 * (R + (0.67*((i + i + 1)*(i + i + 1)) / (i + i + 1))*cos((j + j + 1) / 2));
  98.             sum1 += volume[i][j];
  99.         }
  100.  
  101.     for (int i = 0; i < r ; i++) {
  102.         for (int j = 0; j < sectors; j++)
  103.             cout << square_front[i][j] << " ";
  104.         cout << endl;
  105.     }
  106.  
  107.  
  108.     cout << endl<<endl<<endl;
  109.     for (int i = 0; i < r ; i++) {
  110.         for (int j = 0; j < sectors; j++)
  111.             cout << square_up[i][j] << " ";
  112.         cout << endl;
  113.     }
  114.     cout << endl;
  115.  
  116.     cout << endl << "all volume torus " << 2 * 3.14*R*r*r << " " << sum1;
  117.  
  118. }
  119.  
  120.  
  121.  
  122. int main() {
  123.  
  124.  
  125.     double r = 3, alpha = 0.3489;
  126.     cylindrical(3, 0.3489);
  127.     torus(5, 3, 10);
  128.  
  129.  
  130.     _getch();
  131. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top