Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define int long long
- using namespace std;
- using ld = long double;
- const ld EPS = 0.000000001;
- struct Point {
- ld x{}, y{}, z{};
- Point() = default;
- Point(ld x, ld y) {
- this->x = x;
- this->y = y;
- }
- Point(ld x, ld y, ld z) {
- this->x = x;
- this->y = y;
- this->z = z;
- }
- };
- ld Get(ld a, ld b, ld c, ld d) {
- return (c * b - d * a) / (b - d);
- }
- struct Line {
- Point P;
- Point V;
- Line(Point P, Point V) {
- this->P = P;
- this->V = V;
- }
- static pair<bool, Point> intersect(Line a, Line b) {
- Point I;
- if (abs(a.V.x - b.V.x) < EPS ||
- abs(a.V.y - b.V.y) < EPS ||
- abs(a.V.z - b.V.z) < EPS) {
- return {0, {}};
- }
- I.x = Get(a.P.x, a.V.x, b.P.x, b.V.x);
- ld L = (I.x - a.P.x) / a.V.x;
- I.y = L * a.V.y + a.P.y;
- I.z = L * a.V.z + a.P.z;
- return {1, I};
- }
- };
- struct line2d {
- ld A, B, C;
- line2d(ld x1, ld y1, ld x2, ld y2) {
- A = x1 - x2;
- B = y2 - y1;
- C = - A * x1 - B * y1;
- }
- };
- istream& operator >> (istream& in, Point& a) {
- in >> a.x >> a.y >> a.z;
- return in;
- }
- ld sq(ld x) {
- return x * x;
- }
- ld dist(Point a, Point b) {
- return sqrt(sq(a.x - b.x) + sq(a.y - b.y) + sq(a.z - b.z));
- }
- Point light(-1, -1, -1);
- signed main() {
- ios::sync_with_stdio(false);
- cin.tie(0);
- #ifdef LOCAL
- freopen("input", "r", stdin);
- #endif
- cout << fixed << setprecision(8);
- vector<Point> t1(3), t2(3), t3;
- for (auto& p : t2)
- cin >> p;
- for (auto& p : t1)
- cin >> p;
- for (int i = 0; i < 3; i++) {
- for (int j = 0; j < 3; j++) {
- light = {t2[j].x - t1[i].x, t2[j].y - t1[i].y, 2};
- vector<Line> l1, l2;
- for (auto& p : t1) {
- l1.emplace_back(p, light);
- }
- for (auto& p : t2) {
- l2.emplace_back(p, Point(0, 0, 1));
- }
- bool used[3]; memset(used, 0, sizeof used);
- vector<Point> ans;
- for (int ii = 0; ii < 3; ii++) {
- for (int jj = 0; jj < 3; jj++) {
- auto inter = Line::intersect(l1[ii], l2[jj]);
- if (!used[jj] && inter.first) {
- ans.emplace_back(inter.second.x, inter.second.y, inter.second.z);
- used[jj] = true;
- break;
- }
- }
- }
- if (ans.size() == 3) {
- for (auto& k : ans) {
- cout << k.x << ' ' << k.y << ' ' << k.z << '\n';
- }
- return 0;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement