Dimitrija

Laboratoriski 1 - 2 OOP

Feb 24th, 2021
1,002
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2.  
  3. /*
  4.  
  5. За програмски јазик C.
  6.  
  7. Да се напише структура која ќе опишува отсечка во дводимензионален простор (две точки). Потоа да се напише функција која ќе проверува дали две отсечки се сечат.
  8.  
  9. For example:
  10.  
  11. Input  
  12. -2 -2 2 0
  13. 0 1 1 3
  14. Result
  15. 0
  16.  
  17. */
  18.  
  19. typedef struct tocka{
  20. double x;
  21. double y;
  22. }tocka;
  23.  
  24.  
  25. typedef struct otsecka{
  26. struct tocka t1;
  27. struct tocka t2;
  28. }otsecka;
  29.  
  30. int se_secat(otsecka o1, otsecka o2){
  31.  
  32.     double bx,by,a1x,a1y,a2x,a2y;
  33.     int se_sechat;
  34.  
  35.      bx = o1.t2.x - o1.t1.x;
  36.      by = o1.t2.y - o1.t1.y;
  37.      
  38.      a1x = o2.t1.x - o1.t1.x;
  39.      a1y = o2.t1.y - o1.t1.y;
  40.      
  41.      a2x = o2.t2.x - o1.t2.x;
  42.      a2y = o2.t2.y - o1.t2.y;
  43.      
  44.  if(!((bx*a1y-by*a1x)*(bx*a2y-by*a2x)<=0)){
  45.  return 0;
  46.  }
  47.  
  48.      bx = o2.t2.x - o2.t1.x;
  49.      by = o2.t2.y - o2.t1.y;
  50.      
  51.      a1x = o1.t1.x - o2.t1.x;
  52.      a1y = o1.t1.y - o2.t1.y;
  53.      
  54.      a2x = o1.t2.x - o2.t2.x;
  55.      a2y = o1.t2.y - o2.t2.y;
  56.      
  57.  if(!((bx*a1y-by*a1x)*(bx*a2y-by*a2x)<=0)){
  58.  return 0;
  59.  }
  60.  
  61.  return 1;
  62.  
  63. }
  64.  
  65. int main() {
  66.     double x1, y1, x2, y2;
  67.     scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);
  68.     tocka t1 = { x1, y1 };
  69.     tocka t2 = { x2, y2 };
  70.     otsecka o1 = { t1, t2 };
  71.     scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);
  72.     tocka t3 = { x1, y1 };
  73.     tocka t4 = { x2, y2 };
  74.     otsecka o2 = { t3, t4 };
  75.     printf("%d\n", se_secat(o1, o2));
  76.     return 0;
  77. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×