Advertisement
Guest User

Untitled

a guest
Oct 13th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <time.h>
  4.  
  5.  
  6. #define LINE 128
  7.  
  8. using namespace std;
  9.  
  10. typedef struct point // структура кординаты
  11. {
  12. int x;
  13. int y;
  14. int z;
  15. };
  16.  
  17.  
  18. int main()
  19. {
  20. srand(time(0));
  21. point listofpoints[4]; // МАССИВ точек
  22.  
  23. for (size_t i = 0; i < 4; i++)
  24. {
  25. /*--------------Генерация--------------*/
  26. point temp;
  27. temp.x = -LINE + (rand() % (2*LINE)); temp.y = -LINE + (rand() % (2*LINE)); temp.z = -LINE + (rand() % (2*LINE));
  28. cout << i+1 << ". " << temp.x << " " << temp.y << " " << temp.z << endl; // Вывод в терминал кординат
  29. listofpoints[i] = temp;
  30. /*--------------Генерация--------------*/
  31. }
  32.  
  33. point l1,l2,l3;
  34.  
  35. l1.x = listofpoints[1].x - listofpoints[0].x; l1.y = listofpoints[1].y - listofpoints[0].y; l1.z = listofpoints[1].z - listofpoints[0].z;
  36. l2.x = listofpoints[2].x - listofpoints[0].x; l2.y = listofpoints[2].y - listofpoints[0].y; l2.z = listofpoints[2].z - listofpoints[0].z;
  37. l3.x = listofpoints[3].x - listofpoints[0].x; l3.y = listofpoints[3].y - listofpoints[0].y; l3.z = listofpoints[3].z - listofpoints[0].z;
  38.  
  39. double det = (l1.x * ((l2.y*l3.z) - (l3.y*l2.z))) - (l2.x * ((l1.y*l3.z) - (l1.z*l3.y))) + (l3.x * ((l1.y*l2.z) - (l2.y*l1.z))); // подсчет определителя
  40.  
  41. cout << abs(det) / 6.0 << endl; // вывод объема
  42.  
  43. cin >> l1.x;
  44.  
  45.  
  46. return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement