Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #define LINE 128
- using namespace std;
- typedef struct point // структура кординаты
- {
- int x;
- int y;
- int z;
- };
- double Lenght(point p1, point p2) // формула вычисления длины по двум точкам
- {
- 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));
- }
- double Square(double a, double b, double c) // формула площади треугольника(стороны пирамиды) Герона
- {
- double p = (a + b + c)/2;
- return sqrt(p * (p-a) * (p - b) * (p - c));
- }
- int main(int argc, char const *argv[])
- {
- srand(time(0));
- point listofpoints[4]; // МАССИВ точек
- /* -------------------------------- Ввод --------------------------------*/
- //cout << "Vvedite 4 cordinaty (Format: X Y Z):" << endl;
- 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;
- 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)));
- cout << abs(det) / 6.0 << endl; // вывод общей площади поверхности
- cin >> l1.x;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement