Advertisement
Guest User

Untitled

a guest
Mar 13th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. typedef struct tocka {
  4. // vasiot kod ovde
  5. int x,y;
  6. } tocka;
  7.  
  8. typedef struct otsecka {
  9. // vasiot kod ovde
  10. tocka t1, t2;
  11. } otsecka;
  12.  
  13. int max(int a, int b)
  14. {
  15. if (a>b)
  16. return a;
  17. else
  18. return b;
  19. }
  20. int min(int a, int b)
  21. {
  22. if (a<b)
  23. return a;
  24. else
  25. return b;
  26. }
  27. int naOtsecka(tocka p, tocka q, tocka r)
  28. {
  29. if (q.x <= max(p.x, r.x)&&q.x >= min(p.x, r.x)&&q.y <= max(p.y, r.y) && q.y >= min(p.y, r.y))
  30. return 1;
  31.  
  32. return 0;
  33. }
  34. int orientation(tocka p, tocka q, tocka r)
  35. {
  36. int val = (q.y - p.y) * (r.x - q.x) -
  37. (q.x - p.x) * (r.y - q.y);
  38.  
  39. if (val == 0) return 0;
  40.  
  41. if (val>0)
  42. return 1;
  43. else
  44. return 2;
  45. }
  46. int se_secat(otsecka o1, otsecka o2)
  47. {
  48. // vashiot kod ovde
  49.  
  50. int d1 = orientation(o1.t1, o1.t2, o2.t1);
  51. int d2 = orientation(o1.t1, o1.t2, o2.t2);
  52. int d3 = orientation(o2.t1, o2.t2, o1.t1);
  53. int d4 = orientation(o2.t1, o2.t2, o1.t2);
  54. //printf("%d %d %d %d\n", d1, d2, d3, d4);
  55. if (d1 != d2 && d3 != d4)
  56. return 1;
  57. if (d1 == 0 && naOtsecka(o1.t1, o2.t1, o1.t2)) return 1;
  58. if (d2 == 0 && naOtsecka(o1.t1, o2.t2, o1.t2)) return 1;
  59. if (d3 == 0 && naOtsecka(o2.t1, o1.t1, o2.t2)) return 1;
  60. if (d4 == 0 && naOtsecka(o2.t1, o1.t2, o2.t2)) return 1;
  61.  
  62. return 0;
  63. }
  64. int main() {
  65. float x1, y1, x2, y2;
  66. scanf("%f %f %f %f", &x1, &y1, &x2, &y2);
  67. //printf("%f\n",y1);
  68. tocka t1 = { x1, y1 };
  69. tocka t2 = { x2, y2 };
  70. otsecka o1 = { t1, t2 };
  71. scanf("%f %f %f %f", &x1, &y1, &x2, &y2);
  72. tocka t3 = { x1, y1 };
  73. tocka t4 = { x2, y2 };
  74. otsecka o2 = { t3, t4 };
  75.  
  76. printf("%d\n", se_secat(o1, o2));
  77. return 0;
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement