Advertisement
Guest User

J

a guest
Jun 21st, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.86 KB | None | 0 0
  1. #pragma GCC optimize ("O3")
  2. #include <bits/stdc++.h>
  3. #define pb push_back
  4. #define pf push_front
  5. #define all(a) (a).begin(), (a).end()
  6. #define heap priority_queue
  7. using namespace std;
  8. typedef long long ll;
  9. typedef unsigned long long ull;
  10. typedef long double ld;
  11. typedef pair<ll, ll> pll;
  12. const ll inf = numeric_limits<ll>::max() / 2;
  13. const ld eps = 1e-9;
  14.  
  15. struct vect {
  16.     ld x, y;
  17.     vect() {}
  18.     vect(ld x1, ld y1) {
  19.         x = x1, y = y1;
  20.     }
  21.     vect operator + (vect a) {
  22.         return vect(x + a.x, y + a.y);
  23.     }
  24.     vect operator - (vect a) {
  25.         return vect(x - a.x, y - a.y);
  26.     }
  27.     ld operator * (vect a) {
  28.         return x * a.x + y * a.y;
  29.     }
  30.     ld operator % (vect a) {
  31.         return x * a.y - y * a.x;
  32.     }
  33.     vect operator * (ld k) {
  34.         return vect(x*k, y*k);
  35.     }
  36.     vect rotate(ld a) {
  37.         return vect(x*cos(a) - y * sin(a), x*sin(a) + y * cos(a));
  38.     }
  39. };
  40.  
  41. typedef tuple<ld, ld, ld> line;
  42.  
  43. line equ(vect P, vect Q) {
  44.     ld A = P.y - Q.y;
  45.     ld B = Q.x - P.x;
  46.     ld C = -A * P.x - B * P.y;
  47.     return { A, B, C };
  48. }
  49.  
  50. void solve(vect A, vect B, vect A1, vect B1) {
  51.     vect P((A.x + A1.x) / 2, (A.y + A1.y) / 2);
  52.     vect Q((B.x + B1.x) / 2, (B.y + B1.y) / 2);
  53.     if ((P-Q)*(P-Q) < eps) {
  54.         ld p, q, r;
  55.         tie(p, q, r) = equ(A, B);
  56.         Q = P + vect(p, q);
  57.     }
  58.     ld a, b, c;
  59.     tie(a, b, c) = equ(P, Q);
  60.     vect norm;
  61.     if (a * A.x + b * A.y + c > 0) {
  62.         norm = vect(-a, -b);
  63.     } else {
  64.         norm = vect(a, b);
  65.     }
  66.     ld L = abs(a*A.x + b * A.y + c) / sqrt(a * a + b * b);
  67.     vect A2 = A + norm * (2 * L / sqrt(norm*norm));
  68.     vect A2A1 = A1 - A2;
  69.     cout << P.x << " " << P.y << endl;
  70.     cout << Q.x << " " << Q.y << endl;
  71.     cout << A2A1.x << " " << A2A1.y << endl;
  72. }
  73.  
  74. int main() {
  75.     ios_base::sync_with_stdio(0); cin.tie(0);
  76.     ld x1, y1, x2, y2, x1_, y1_, x2_, y2_;
  77.     cin >> x1 >> y1 >> x2 >> y2 >> x1_ >> y1_ >> x2_ >> y2_;
  78.     cout << fixed;
  79.     solve({ x1, y1 }, { x2, y2 }, { x1_, y1_ }, { x2_, y2_ });
  80.     return 0;
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement