Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. bool IsConvex(vector <point> &p) {
  2. int n = p.size();
  3. if (n <=1)
  4. {
  5. return true;
  6. }
  7. if (n == 2)
  8. {
  9. return false;
  10. }
  11. int state;
  12. int stateprev;
  13. int check = -1345;
  14. for (int i = 0; i < n; ++i)
  15. {
  16. for (int j = 0; j < n; ++j)
  17. {
  18. if (j != i && j != (i + 1) % n)
  19. {
  20. state = Classify(p[i].x, p[i].y, p[(i + 1) % n].x, p[(i + 1) % n].y, p[j].x, p[j].y);
  21. if (state == BEHIND || state == BETWEEN || state == BEYOND)
  22. {
  23. continue;
  24. }
  25. if (check != -1345 && check != state)
  26. {
  27. return false;
  28. }
  29. if (state == RIGHT || state == LEFT)
  30. {
  31. check = state;
  32. }
  33. }
  34. }
  35. }
  36. return true;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement