Advertisement
Tbl_Mne_Ne_Dryg

Untitled

Dec 22nd, 2022
472
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.43 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define int long long
  3.  
  4. using namespace std;
  5. using ld = long double;
  6. const ld EPS = 0.000000001;
  7.  
  8. struct Point {
  9.   ld x{}, y{}, z{};
  10.   Point() = default;
  11.   Point(ld x, ld y) {
  12.     this->x = x;
  13.     this->y = y;
  14.   }
  15.   Point(ld x, ld y, ld z) {
  16.     this->x = x;
  17.     this->y = y;
  18.     this->z = z;
  19.   }
  20. };
  21.  
  22. ld Get(ld a, ld b, ld c, ld d) {
  23.   return (c * b - d * a) / (b - d);
  24. }
  25.  
  26. struct Line {
  27.   Point P;
  28.   Point V;
  29.   Line(Point P, Point V) {
  30.     this->P = P;
  31.     this->V = V;
  32.   }
  33.   static pair<bool, Point> intersect(Line a, Line b) {
  34.     Point I;
  35.     if (abs(a.V.x - b.V.x) < EPS ||
  36.         abs(a.V.y - b.V.y) < EPS ||
  37.         abs(a.V.z - b.V.z) < EPS) {
  38.       return {0, {}};
  39.     }
  40.     I.x = Get(a.P.x, a.V.x, b.P.x, b.V.x);
  41.     ld L = (I.x - a.P.x) / a.V.x;
  42.     I.y = L * a.V.y + a.P.y;
  43.     I.z = L * a.V.z + a.P.z;
  44.     return {1, I};
  45.   }
  46. };
  47.  
  48. struct line2d {
  49.   ld A, B, C;
  50.   line2d(ld x1, ld y1, ld x2, ld y2) {
  51.     A = x1 - x2;
  52.     B = y2 - y1;
  53.     C = - A * x1 - B * y1;
  54.   }
  55. };
  56.  
  57. istream& operator >> (istream& in, Point& a) {
  58.   in >> a.x >> a.y >> a.z;
  59.   return in;
  60. }
  61.  
  62. ld sq(ld x) {
  63.   return x * x;
  64. }
  65.  
  66. ld dist(Point a, Point b) {
  67.   return sqrt(sq(a.x - b.x) + sq(a.y - b.y) + sq(a.z - b.z));
  68. }
  69.  
  70. Point light(-1, -1, -1);
  71.  
  72. signed main() {
  73.   ios::sync_with_stdio(false);
  74.   cin.tie(0);
  75. #ifdef LOCAL
  76.   freopen("input", "r", stdin);
  77. #endif
  78.   cout << fixed << setprecision(8);
  79.   vector<Point> t1(3), t2(3), t3;
  80.   for (auto& p : t2)
  81.     cin >> p;
  82.   for (auto& p : t1)
  83.     cin >> p;
  84.   for (int i = 0; i < 3; i++) {
  85.     for (int j = 0; j < 3; j++) {
  86.       light = {t2[j].x - t1[i].x, t2[j].y - t1[i].y, 2};
  87.       vector<Line> l1, l2;
  88.       for (auto& p : t1) {
  89.         l1.emplace_back(p, light);
  90.       }
  91.       for (auto& p : t2) {
  92.         l2.emplace_back(p, Point(0, 0, 1));
  93.       }
  94.       bool used[3]; memset(used, 0, sizeof used);
  95.       vector<Point> ans;
  96.       for (int ii = 0; ii < 3; ii++) {
  97.         for (int jj = 0; jj < 3; jj++) {
  98.           auto inter = Line::intersect(l1[ii], l2[jj]);
  99.           if (!used[jj] && inter.first) {
  100.             ans.emplace_back(inter.second.x, inter.second.y, inter.second.z);
  101.             used[jj] = true;
  102.             break;
  103.           }
  104.         }
  105.       }
  106.       if (ans.size() == 3) {
  107.         for (auto& k : ans) {
  108.           cout << k.x << ' ' << k.y << ' ' << k.z << '\n';
  109.         }
  110.         return 0;
  111.       }
  112.     }
  113.   }
  114.  
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement