Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- typedef struct tocka {
- // vasiot kod ovde
- int x,y;
- } tocka;
- typedef struct otsecka {
- // vasiot kod ovde
- tocka t1, t2;
- } otsecka;
- int max(int a, int b)
- {
- if (a>b)
- return a;
- else
- return b;
- }
- int min(int a, int b)
- {
- if (a<b)
- return a;
- else
- return b;
- }
- int naOtsecka(tocka p, tocka q, tocka r)
- {
- 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))
- return 1;
- return 0;
- }
- int orientation(tocka p, tocka q, tocka r)
- {
- int val = (q.y - p.y) * (r.x - q.x) -
- (q.x - p.x) * (r.y - q.y);
- if (val == 0) return 0;
- if (val>0)
- return 1;
- else
- return 2;
- }
- int se_secat(otsecka o1, otsecka o2)
- {
- // vashiot kod ovde
- int d1 = orientation(o1.t1, o1.t2, o2.t1);
- int d2 = orientation(o1.t1, o1.t2, o2.t2);
- int d3 = orientation(o2.t1, o2.t2, o1.t1);
- int d4 = orientation(o2.t1, o2.t2, o1.t2);
- //printf("%d %d %d %d\n", d1, d2, d3, d4);
- if (d1 != d2 && d3 != d4)
- return 1;
- if (d1 == 0 && naOtsecka(o1.t1, o2.t1, o1.t2)) return 1;
- if (d2 == 0 && naOtsecka(o1.t1, o2.t2, o1.t2)) return 1;
- if (d3 == 0 && naOtsecka(o2.t1, o1.t1, o2.t2)) return 1;
- if (d4 == 0 && naOtsecka(o2.t1, o1.t2, o2.t2)) return 1;
- return 0;
- }
- int main() {
- float x1, y1, x2, y2;
- scanf("%f %f %f %f", &x1, &y1, &x2, &y2);
- //printf("%f\n",y1);
- tocka t1 = { x1, y1 };
- tocka t2 = { x2, y2 };
- otsecka o1 = { t1, t2 };
- scanf("%f %f %f %f", &x1, &y1, &x2, &y2);
- tocka t3 = { x1, y1 };
- tocka t4 = { x2, y2 };
- otsecka o2 = { t3, t4 };
- printf("%d\n", se_secat(o1, o2));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement