Advertisement
Guest User

Untitled

a guest
Apr 18th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. int Convex(vector<Point> vector_of_points)
  2.  
  3. {
  4. int i, j, k;
  5. int flag = 0;
  6. double z;
  7.  
  8. if (vector_of_points.size() < 3)
  9. return(0);
  10.  
  11. for (i = 0; i < vector_of_points.size(); i++)
  12. {
  13. j = (i + 1) % vector_of_points.size();
  14. k = (i + 2) % vector_of_points.size();
  15. z = (vector_of_points[j].x - vector_of_points[i].x) * (vector_of_points[k].y - vector_of_points[j].y);
  16. z -= (vector_of_points[j].y - vector_of_points[i].y) * (vector_of_points[k].x - vector_of_points[j].x);
  17. if (z < 0)
  18. flag |= 1;
  19. else if (z > 0)
  20. flag |= 2;
  21. if (flag == 3) {
  22. cout << "\n\tConcave(вогнутый)";
  23. return (0);
  24. }
  25. }
  26.  
  27. if (flag != 0)
  28. cout << "\n\tConvex(выпуклый)";
  29. else
  30. return(0);
  31. }
  32.  
  33. void inputPoints(vector<Point> &vector_of_points)
  34. {
  35. glClear(GL_COLOR_BUFFER_BIT);
  36. glColor3f(1, 0, 0);
  37. glBegin(GL_LINE_LOOP);
  38. int amount_of_points;
  39. cout << "amount of points: ";
  40. cin >> amount_of_points;
  41. for (int i = 0; i < amount_of_points; i++)
  42. {
  43. Point temp;
  44. cout << "point " << i + 1 << endl;
  45. cout << "\tinput x ";
  46. cin >> temp.x;
  47. cout << "\tinput y ";
  48. cin >> temp.y;
  49. glVertex2f(temp.x, temp.y);
  50. vector_of_points.push_back(temp);
  51. }
  52. glEnd();
  53. glFlush();
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement