Hafixie93

Lab simulation 4.0

Dec 7th, 2020
329
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include<math.h>
  3.  
  4.  
  5. struct point {
  6.  
  7.     double x;
  8.     double y;
  9.  
  10. };
  11.  
  12.  
  13. main()
  14. {
  15.  
  16.     int speed = 20;
  17.     double defender_position_x = 0;
  18.     double defender_position_y = 60;
  19.  
  20.  
  21.  
  22.     struct point target_position[15];
  23.     struct point defender_position[15];
  24.  
  25.     //defender_position
  26.  
  27.     FILE *myFile;
  28.     myFile = fopen("Point.txt", "r");
  29.  
  30.  
  31.     int i;
  32.  
  33.     for (i = 0; i < 15; i++)
  34.     {
  35.         fscanf(myFile, "%lf %lf", &target_position[i].x , &target_position[i].y );
  36.     }
  37.  
  38.     for (i = 0; i < 15; i++)
  39.     {
  40.         printf("Number is: %lf %lf\n\n", target_position[i].x, target_position[i].y);
  41.     }
  42.  
  43.  
  44.  
  45.  
  46.     for (int t=0; t<12; t++){
  47.  
  48.         double distance = sqrt((((target_position[t].x - defender_position_x)*(target_position[t].x - defender_position_x)) + (target_position[t].y - defender_position_y)*target_position[t].y - defender_position_y));
  49.  
  50.         double sin = ((target_position[t].y) - (defender_position_y)) / distance;
  51.  
  52.         double cos = ((target_position[t].x) - (defender_position_x)) / distance;
  53.  
  54.  
  55.         printf("distance: %lf" , distance);
  56.  
  57.  
  58.  
  59.  
  60.     }
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75. }
Add Comment
Please, Sign In to add comment