didedoshka

is point within the angle or not

Nov 24th, 2020
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.75 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <queue>
  5. #include <cmath>
  6. #include <set>
  7. #include <stack>
  8. #include <bitset>
  9. #include <map>
  10. #include <ctime>
  11. #include <numeric>
  12. #include <random>
  13.  
  14.  
  15. #ifndef M_PI
  16. #define M_PI 3.141592653589
  17. #endif
  18. #define int long long
  19. #define uint unsigned long long
  20. #define double long double
  21.  
  22. #ifdef TIME
  23. #define start cin.tie(NULL); cout.tie(NULL); cout.setf(ios::fixed); cout.precision(10); ios_base::sync_with_stdio(false);int32_t START = clock()
  24. #define finish cout << "\ntime: " << (clock() - START) / (CLOCKS_PER_SEC * 1.0); return 0
  25. #endif
  26.  
  27. #ifndef TIME
  28. #define start cin.tie(NULL); cout.tie(NULL); cout.setf(ios::fixed); cout.precision(10); ios_base::sync_with_stdio(false)
  29. #define finish return 0
  30. #endif
  31.  
  32. using namespace std;
  33.  
  34.  
  35. //vector input
  36. template<typename T>
  37. istream &operator>>(istream &is, vector<T> &vec) {
  38.     for (auto &i : vec) {
  39.         cin >> i;
  40.     }
  41.     return is;
  42. }
  43.  
  44. //pair output
  45. template<typename E>
  46. ostream &operator<<(ostream &os, pair<E, E> &t) {
  47.     os << t.first << ' ' << t.second;
  48.     return os;
  49. }
  50.  
  51. //"map" pair output
  52. template<typename E>
  53. ostream &operator<<(ostream &os, pair<const E, E> &t) {
  54.     os << t.first << ' ' << t.second;
  55.     return os;
  56. }
  57.  
  58. //vector output
  59. template<typename T>
  60. ostream &operator<<(ostream &os, vector<T> &vec) {
  61.     for (T i : vec) {
  62.         os << i << ' ';
  63.     }
  64.     return os;
  65. }
  66.  
  67. //2 dimensional vector output
  68. template<typename T>
  69. ostream &operator<<(ostream &os, vector<vector<T> > &vec) {
  70.     for (vector<T> i : vec) {
  71.         os << i << '\n';
  72.     }
  73.     return os;
  74. }
  75.  
  76. struct point {
  77.     double x, y;
  78.  
  79.     point(double _x, double _y) : x(_x), y(_y) {}
  80.  
  81.     point() : x(0), y(0) {}
  82. };
  83.  
  84. struct vec {
  85.     double x, y;
  86.  
  87.     vec(point begin, point end) {
  88.         x = end.x - begin.x;
  89.         y = end.y - begin.y;
  90.     }
  91.  
  92.     vec(point end) {
  93.         x = end.x;
  94.         y = end.y;
  95.     }
  96.  
  97.     double length() {
  98.         return sqrt(x * x + y * y);
  99.     }
  100.  
  101.     vec operator+(vec &b) const {
  102.         vec c(point(x + b.x, y + b.y));
  103.         return c;
  104.     }
  105.  
  106.     double operator*(vec &b) const {
  107.         return x * b.x + y * b.y;
  108.     }
  109.  
  110.     double operator^(vec &b) const {
  111.         return x * b.y - y * b.x;
  112.     }
  113. };
  114.  
  115. int32_t main() {
  116.     start;
  117.  
  118.     int xp, yp, xa, ya, xb, yb, xo, yo;
  119.     cin >> xa >> ya;
  120.     cin >> xo >> yo;
  121.     cin >> xb >> yb;
  122.     cin >> xp >> yp;
  123.  
  124.     point a(xa, ya), o(xo, yo), b(xb, yb), p(xp, yp);
  125.  
  126.     vec oa(o, a), op(o, p), ob(o, b);
  127.  
  128.  
  129.     if (((ob ^ op) >= 0 && (op ^ oa) >= 0 && (ob ^ oa) >= 0) || ((oa ^ op) >= 0 && (op ^ ob) >= 0 && (oa ^ ob) >= 0)) {
  130.         cout << "YES" << '\n';
  131.     } else {
  132.         cout << "NO" << '\n';
  133.     }
  134.  
  135.     finish;
  136. }
  137.  
Advertisement
Add Comment
Please, Sign In to add comment