fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. typedef double ftype;
  6. typedef complex<ftype> point;
  7. typedef complex<point> quater;
  8. #define qA real()
  9. #define qB imag()
  10. #define qs qA.real()
  11. #define qx qA.imag()
  12. #define qy qB.real()
  13. #define qz qB.imag()
  14.  
  15. quater operator * (quater a, quater b)
  16. {
  17. return {{a.qA * b.qA - a.qB * conj(b.qB)},
  18. {a.qA * b.qB + a.qB * conj(b.qA)}};
  19. }
  20.  
  21. quater conj(quater a)
  22. {
  23. return {conj(a.qA), - a.qB};
  24. }
  25.  
  26. ftype norm(quater a)
  27. {
  28. return (a * conj(a)).qs;
  29. }
  30.  
  31. ftype abs(quater a)
  32. {
  33. return sqrt(norm(a));
  34. }
  35.  
  36. quater operator / (quater a, quater b)
  37. {
  38. return a * conj(b) / point(norm(b));
  39. }
  40.  
  41. quater vec(ftype x, ftype y, ftype z)
  42. {
  43. return {{0, x}, {y, z}};
  44. }
  45.  
  46. quater vec(quater a)
  47. {
  48. return a -= a.qs;
  49. }
  50.  
  51. ftype dot(quater a, quater b)
  52. {
  53. return -(a * b).qs;
  54. }
  55.  
  56. quater cross(quater a, quater b)
  57. {
  58. return vec(a * b);
  59. }
  60.  
  61. ftype mix(quater a, quater b, quater c)
  62. {
  63. return dot(a, cross(b, c));
  64. }
  65.  
  66. quater conj(quater a, quater g)
  67. {
  68. return g * a / g;
  69. }
  70.  
  71. quater rotation(quater i, ftype phi)
  72. {
  73. return point(cos(phi / 2)) + i * point(sin(phi / 2));
  74. }
  75.  
  76. quater rotate(quater a, quater i, ftype phi)
  77. {
  78. return conj(a, rotation(i, phi));
  79. }
  80.  
  81. signed main()
  82. {
  83. ios::sync_with_stdio(0);
  84. cin.tie(0);
  85. const double pi = acos(-1.);
  86. quater A = vec(0, 0, 1);
  87. quater B = vec(1, 0, 0);
  88. double phi = pi / 4;
  89. cout << rotate(B, A, phi) << "\n";
  90. return 0;
  91. }
  92.  
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
((0,0.707107),(0.707107,0))