Advertisement
Alex9090

Untitled

Mar 19th, 2018
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. double triangleArea(punct a, punct b, punct c) {
  2. return abs((a.x * (b.y - c.y) + b.x * (c.y - a.y) + c.x * (a.y - b.y)) / 2);
  3. }
  4.  
  5. bool pointInTriangle(punct a, punct b, punct c, punct m) {
  6. if (triangleArea(a, b, c) == triangleArea(a, b, m) + triangleArea(a, c, m) + triangleArea(b, c, m))
  7. return true;
  8. return false;
  9. }
  10.  
  11.  
  12.  
  13. void desen() // procedura desenare
  14. {
  15. if (p.size() >= 2) {
  16. glLineWidth(3);
  17. glBegin(GL_LINES);
  18. glColor3f(0, 0, 0);
  19.  
  20. for (int i = 0; i < p.size() - 1; i++) {
  21. glVertex2i(p[i].x, p[i].y);
  22. glVertex2i(p[i + 1].x, p[i + 1].y);
  23. }
  24.  
  25. if (p.size() == n) {
  26. glVertex2i(p[0].x, p[0].y);
  27. glVertex2i(p[n - 1].x, p[n - 1].y);
  28.  
  29.  
  30. }
  31. glEnd();
  32.  
  33. if (p.size() == n) {
  34. int k = 0;
  35. for (int i = 1; i < p.size(); i++) {
  36. if (p[k].x > p[i].x)
  37. k = i;
  38. }
  39.  
  40.  
  41.  
  42. glEnable(GL_POINT_SMOOTH);
  43. glPointSize(10);
  44. glBegin(GL_POINTS);
  45.  
  46.  
  47. for (int i = 0; i < p.size(); i++) {
  48. punct v, w, pct;
  49. if (i == p.size() - 1) {
  50. v = vect[i];
  51. w = vect[0];
  52. pct = p[0];
  53. }
  54. else {
  55. v = vect[i];
  56. w = vect[i + 1];
  57. pct = p[i + 1];
  58. }
  59. if ((prodVect(v, w).z * prodVect(vect[k == 0 ? vect.size() - 1 : k - 1], vect[k]).z) > 0) {
  60. int nr = 0;
  61. punct a, b, c;
  62. if (i == p.size() - 1) {
  63. a = p[i];
  64. b = p[0];
  65. c = p[1];
  66. }
  67. else if (i == p.size() - 2) {
  68. a = p[i];
  69. b = p[i + 1];
  70. c = p[0];
  71. }
  72. else {
  73. a = p[i];
  74. b = p[i + 1];
  75. c = p[i + 2];
  76. }
  77. for (int j = 0; j < p.size(); j++) {
  78. if (pointInTriangle(a, b, c, p[j]))
  79. nr++;
  80. }
  81. cout << nr;
  82. if (nr == 3) {
  83. vfPrin.push_back(b);
  84. }
  85. glColor3f(1, 0, 0);
  86. }
  87. else {
  88. glColor3f(0, 0, 1);
  89. }
  90. glVertex2i(pct.x, pct.y);
  91. }
  92.  
  93.  
  94.  
  95. glEnd();
  96. glColor3f(0, 0, 0);
  97. for (int i = 0; i < vfPrin.size(); i++) {
  98. glRasterPos2i(vfPrin[i].x + 15, vfPrin[i].y + 15);
  99. glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, 'P');
  100. }
  101. }
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108. }
  109.  
  110. glFlush();
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement