fork(6) download
  1. #include <iostream>
  2. #define _USE_MATH_DEFINES
  3. #include <math.h>
  4. #include <iomanip>
  5.  
  6. using namespace std;
  7.  
  8. struct Point
  9. {
  10. double x, y;
  11. };
  12.  
  13. struct Vector2
  14. {
  15. double x, y;
  16. };
  17.  
  18. double deg(double rad) // Zamień radiany na stopnie
  19. {
  20. return rad/M_PI*180;
  21. }
  22. double rad(double deg) // Zamień stopnie na radiany
  23. {
  24. return deg*M_PI/180;
  25. }
  26.  
  27. double angle(Vector2 a, Vector2 b) // oblicz kąt pomiędzy wektorami
  28. {
  29. return acos ( (a.x * b.x + a.y * b.y) / ( sqrt( pow(a.x, 2) + pow(a.y, 2) ) * sqrt( pow(b.x, 2) + pow(b.y, 2) )) );;
  30. }
  31.  
  32. Point rotate(Point A, Point S, double alpha) // oblicz kąt pomiędzy wektorami
  33. {
  34. Point B;// szukany punkt
  35. if(A.x == S.x && A.y == S.y)
  36. return A;
  37. Vector2 a, b; // wektory a i b
  38. a.x = A.x - S.x;
  39. a.y = A.y - S.y;
  40.  
  41. double r = sqrt(pow(a.x, 2) + pow(a.y, 2)); // długość wektora a
  42.  
  43. Point tmp; tmp.x = S.x+1; tmp.y = S.y; // punkt pomocniczy
  44. Vector2 t; // wektor pomocniczy
  45. t.x = 2; // zapis troszkę sktócony :)
  46. t.y = 0;
  47.  
  48. double beta = angle(a, t); // kąt pomiędzy wektorami a i t
  49.  
  50. double gamma = beta + alpha;// kąt pomiędzy wektoami a i b
  51.  
  52. Vector2 c; // kolejny wektor pomocniczny(dla zobrazowania)
  53. c.x = r;
  54. c.y = 0;
  55.  
  56. b.x = cos(gamma) * r;// C.x
  57. b.y = sin(gamma) * r;
  58.  
  59. // oblicz pozycję B mając dany wektor b i punkt S
  60. B.x = S.x + b.x;
  61. B.y =S.y + b.y;
  62.  
  63. return B;
  64. }
  65.  
  66. int main()
  67. {
  68. Point a, s;
  69. double alfa;
  70. // Wejście:
  71. // Ax Ay Sx Sy Alfa
  72. // Wyjście:
  73. // Bx By
  74. while(cin>>a.x>>a.y>>s.x>>s.y>>alfa)
  75. {
  76. Point b = rotate(a, s, rad(alfa));// oblicz pozycje punktu B
  77. cout<<fixed <<b.x<<" "<<b.y<<" "<<endl; // Wypisz pozycje punktu B
  78. }
  79.  
  80. return 0;
  81. }
Success #stdin #stdout 0.02s 2860KB
stdin
2 8 1 2 180
2 8 1 2 45
10 10 5 5 180
5 5 -1 -1 360
3 3 1 1 90
5 5 0 0 45
stdout
-0.000000 -4.000000 
-2.535534 6.949747 
-0.000000 0.000000 
5.000000 5.000000 
-1.000000 3.000000 
0.000000 7.071068