﻿

# Presek na tocki lab 1.2

Mar 11th, 2020
228
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #include <stdio.h>
2.
3. typedef struct point {
4.     float x;
5.     float y;
6. } point;
7.
8. typedef struct segment {
9.     point a;
10.     point b;
11. } segment;
12. typedef struct prava {
13.     float k;
14.     point t;
15. } prava;
16.
17. int intersect(segment s1, segment s2) {
18.     prava p1,p2;
19.     p1.k=(s1.b.y-s1.a.y)/(s1.b.x-s1.a.x);
20.     p1.t=s1.a;
21.     p2.k=(s2.b.y-s2.a.y)/(s2.b.x-s2.a.x);
22.     p2.t=s2.a;
23.     if(p1.k==p2.k)
24.         return 0;
25.     point t1;
26.     t1.x=(p2.k * p2.t.x - p1.k *p1.t.x + p1.t.y - p2.t.y)/(p2.k - p1.k);
27.     t1.y=p1.k * (t1.x - p1.t.x) + p1.t.y;
28.     int s;
29.     s=(((t1.x<=s1.a.x)&&(t1.x>=s1.b.x))||((t1.x>=s1.a.x)&&(t1.x<=s1.b.x)))&&(((t1.x<=s2.a.x)&&(t1.x>=s2.b.x))||((t1.x>=s2.a.x)&&(t1.x<=s2.b.x)));
30.     return s;
31.
32. }
33. int main (){
34. float x1, y1, x2, y2;
35.     scanf("%f %f %f %f", &x1, &y1, &x2, &y2);
36.     point t1 = { x1, y1 };
37.     point t2 = { x2, y2 };
38.     segment o1 = { t1, t2 };
39.     scanf("%f %f %f %f", &x1, &y1, &x2, &y2);
40.     point t3 = { x1, y1 };
41.     point t4 = { x2, y2 };
42.     segment o2 = { t3, t4 };
43.     printf("%d\n", intersect(o1, o2));
44.     return 0;
45. }
RAW Paste Data