Advertisement
Guest User

Untitled

a guest
Oct 13th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. #define LINE 128
  5.  
  6. using namespace std;
  7.  
  8. typedef struct point // структура кординаты
  9. {
  10. int x;
  11. int y;
  12. int z;
  13. };
  14.  
  15. double Lenght(point p1, point p2) // формула вычисления длины по двум точкам
  16. {
  17. return sqrt((p2.x-p1.x)*(p2.x-p1.x) + (p2.y-p1.y)*(p2.y-p1.y) + (p2.z-p1.z)*(p2.z-p1.z));
  18. }
  19.  
  20. double Square(double a, double b, double c) // формула площади треугольника(стороны пирамиды) Герона
  21. {
  22. double p = (a + b + c)/2;
  23. return sqrt(p * (p-a) * (p - b) * (p - c));
  24. }
  25.  
  26.  
  27. int main(int argc, char const *argv[])
  28. {
  29. srand(time(0));
  30. point listofpoints[4]; // МАССИВ точек
  31. /* -------------------------------- Ввод --------------------------------*/
  32. //cout << "Vvedite 4 cordinaty (Format: X Y Z):" << endl;
  33. for (size_t i = 0; i < 4; i++)
  34. {
  35.  
  36. point temp;
  37. temp.x = -LINE + (rand() % (2*LINE)); temp.y = -LINE + (rand() % (2*LINE)); temp.z = -LINE + (rand() % (2*LINE));
  38. cout << i+1 << ". " << temp.x << " " << temp.y << " " << temp.z << endl;
  39. listofpoints[i] = temp;
  40. }
  41.  
  42. /* -------------------------------- Ввод --------------------------------*/
  43.  
  44. point l1,l2,l3;
  45.  
  46. l1.x = listofpoints[1].x - listofpoints[0].x; l1.y = listofpoints[1].y - listofpoints[0].y; l1.z = listofpoints[1].z - listofpoints[0].z;
  47. l2.x = listofpoints[2].x - listofpoints[0].x; l2.y = listofpoints[2].y - listofpoints[0].y; l2.z = listofpoints[2].z - listofpoints[0].z;
  48. l3.x = listofpoints[3].x - listofpoints[0].x; l3.y = listofpoints[3].y - listofpoints[0].y; l3.z = listofpoints[3].z - listofpoints[0].z;
  49.  
  50. 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)));
  51.  
  52. cout << abs(det) / 6.0 << endl; // вывод общей площади поверхности
  53.  
  54. cin >> l1.x;
  55.  
  56.  
  57. return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement