Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <time.h>
- #define LINE 128
- using namespace std;
- typedef struct point // структура кординаты
- {
- int x;
- int y;
- int z;
- };
- double Volume(point l1, point l2, point l3)
- {
- return ((l1.x*l2.y*l3.z) + (l1.y * l2.z * l3.x) + (l1.z * l2.x * l3.y) - (l1.z * l2.y * l3.x) - (l1.x * l2.z * l3.y) - (l1.y * l2.x * l3.z)) / 6.0;
- }
- int main()
- {
- srand(time(0));
- point listofpoints[4]; // МАССИВ точек
- for (size_t i = 0; i < 4; i++)
- {
- /*--------------Генерация--------------*/
- point temp;
- temp.x = -LINE + (rand() % (2*LINE)); temp.y = -LINE + (rand() % (2*LINE)); temp.z = -LINE + (rand() % (2*LINE));
- cout << i+1 << ". " << temp.x << " " << temp.y << " " << temp.z << endl; // Вывод в терминал кординат
- listofpoints[i] = temp;
- /*--------------Генерация--------------*/
- }
- point l1,l2,l3;
- l1.x = listofpoints[1].x - listofpoints[0].x; l1.y = listofpoints[1].y - listofpoints[0].y; l1.z = listofpoints[1].z - listofpoints[0].z;
- l2.x = listofpoints[2].x - listofpoints[0].x; l2.y = listofpoints[2].y - listofpoints[0].y; l2.z = listofpoints[2].z - listofpoints[0].z;
- l3.x = listofpoints[3].x - listofpoints[0].x; l3.y = listofpoints[3].y - listofpoints[0].y; l3.z = listofpoints[3].z - listofpoints[0].z;
- cout << abs(Volume(l1,l2,l3)) << endl; // вывод объема
- cin >> l1.x;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement