Advertisement
barbaravladi

geom3

Dec 15th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. #define fixlen 10000
  2.  
  3. #include <stdio.h>
  4. #include <math.h>
  5.  
  6. double getCos(double x, double y, double x1, double y1, double x2, double y2);
  7. double getVisionAngle(double* px, double* py, int len);
  8.  
  9. int main(void)
  10. {
  11. double pointsX[fixlen], pointsY[fixlen], a;
  12.  
  13. FILE *fin;
  14. int len = 0;
  15. fin = fopen("input.txt", "r");
  16.  
  17. if (!fin)
  18. {
  19. printf("File opening error\n");
  20. return -1;
  21. }
  22.  
  23. for (int i = 0; i < fixlen; i++)
  24. {
  25. if (fscanf(fin, "%lf", &a) != 1) break;
  26. pointsX[i] = i;
  27. if (fscanf(fin, "%lf", &a) != 1) break;
  28. pointsY[i] = i;
  29. len++;
  30.  
  31. }
  32. printf("%lf" , getVisionAngle(pointsX, pointsY, len));
  33. fclose(fin);
  34.  
  35. return 0;
  36. }
  37.  
  38. double getCos(double x, double y, double x1, double y1, double x2, double y2)
  39. {
  40. double a, b, c, cos;
  41. a = pow((x1-x2), 2) + pow((y1-y2), 2);
  42. b = pow((x-x2), 2) + pow((y-y2), 2);
  43. c = pow((x1-x), 2) + pow((y1-y), 2);
  44. cos = (b + c - a) / (2 * sqrt(b*c));
  45. return cos;
  46. }
  47.  
  48. double getVisionAngle(double* px, double* py, int len)
  49. {
  50. double x, y, mincos, curcos, x1, x2, y1, y2;
  51.  
  52. scanf("%lf %lf", &x, &y);
  53. mincos = 2;
  54. for (int i = 0; i < len - 1; i++)
  55. {
  56. for (int j = i + 1; j < len; j++)
  57. {
  58. x1 = px[i];
  59. y1 = py[i];
  60. x2 = px[j];
  61. y2 = py[j];
  62. curcos = getCos(x, y, x1, y1, x2, y2);
  63. if (curcos < mincos) mincos = curcos;
  64. }
  65. }
  66. mincos = acos(mincos);
  67. return mincos;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement