Advertisement
zhukov000

Example geometry

Apr 3rd, 2021
784
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. using LL = long long;
  4.  
  5. const long double PI = acos(-1.0);
  6.  
  7. struct PT { LL x, y; };
  8.  
  9. struct V
  10. {
  11.   LL x, y;
  12.   V(LL _x=0, LL _y=0): x(_x), y(_y) { }
  13.   V(PT p): x(p.x), y(p.y) { }
  14.   V(PT p1, PT p2): x(p2.x-p1.x), y(p2.y-p1.y) {}
  15.  
  16.   LL operator*(V v2)
  17.   {
  18.     return x * v2.x + y * v2.y;
  19.   }
  20.  
  21.   LL operator%(V v2)
  22.   {
  23.     return x * v2.y - y * v2.x;
  24.   }
  25.  
  26.   long double len()
  27.   {
  28.     return hypot(x, y); // sqrt(x*x + y*y)
  29.   }
  30. };
  31.  
  32. long double fi(V v1, V v2)
  33. {
  34.   return atan2(v1 % v2, v1 * v2); // -pi ... pi
  35. }
  36.  
  37. istream& operator>>(istream& in, PT& p)
  38. {
  39.   in >> p.x >> p.y;
  40.   return in;
  41. }
  42.  
  43. ostream& operator<<(ostream& out, V v)
  44. {
  45.   out << v.x << ' ' << v.y;
  46.   return out;
  47. }
  48.  
  49. int main()
  50. {
  51.   #ifdef AZHUKOV
  52.   freopen("input.txt", "r", stdin);
  53.   #endif // AZHUKOV
  54.  
  55.   PT A, B;
  56.   cin >> A >> B;
  57.  
  58.   V AB(A,B);
  59.   cout << AB;
  60.  
  61.   // OA.operator*(OB)
  62.   return 0;
  63. }
  64.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement