Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- /*
- За програмски јазик C.
- Да се напише структура која ќе опишува отсечка во дводимензионален простор (две точки). Потоа да се напише функција која ќе проверува дали две отсечки се сечат.
- For example:
- Input
- -2 -2 2 0
- 0 1 1 3
- Result
- 0
- */
- typedef struct tocka{
- double x;
- double y;
- }tocka;
- typedef struct otsecka{
- struct tocka t1;
- struct tocka t2;
- }otsecka;
- int se_secat(otsecka o1, otsecka o2){
- double bx,by,a1x,a1y,a2x,a2y;
- int se_sechat;
- bx = o1.t2.x - o1.t1.x;
- by = o1.t2.y - o1.t1.y;
- a1x = o2.t1.x - o1.t1.x;
- a1y = o2.t1.y - o1.t1.y;
- a2x = o2.t2.x - o1.t2.x;
- a2y = o2.t2.y - o1.t2.y;
- if(!((bx*a1y-by*a1x)*(bx*a2y-by*a2x)<=0)){
- return 0;
- }
- bx = o2.t2.x - o2.t1.x;
- by = o2.t2.y - o2.t1.y;
- a1x = o1.t1.x - o2.t1.x;
- a1y = o1.t1.y - o2.t1.y;
- a2x = o1.t2.x - o2.t2.x;
- a2y = o1.t2.y - o2.t2.y;
- if(!((bx*a1y-by*a1x)*(bx*a2y-by*a2x)<=0)){
- return 0;
- }
- return 1;
- }
- int main() {
- double x1, y1, x2, y2;
- scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);
- tocka t1 = { x1, y1 };
- tocka t2 = { x2, y2 };
- otsecka o1 = { t1, t2 };
- scanf("%lf %lf %lf %lf", &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