canonical_quaternions.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // Define some canonical quaternions for floats and doubles
  2. // A Quaternion, q, is defined here as an arrays of four scalars (x,y,z,w),
  3. // such that q = x*i + y*j + z*k + w
  4. namespace igl
  5. {
  6. # define SQRT_2_OVER_2 0.707106781f
  7. // Float versions
  8. // Identity
  9. const float IDENTITY_QUAT_F[4] = {0,0,0,1};
  10. // The following match the Matlab canonical views
  11. // X point right, Y pointing up and Z point out
  12. const float XY_PLANE_QUAT_F[4] = {0,0,0,1};
  13. // X points right, Y points *in* and Z points up
  14. const float XZ_PLANE_QUAT_F[4] = {-SQRT_2_OVER_2,0,0,SQRT_2_OVER_2};
  15. // X points out, Y points right, and Z points up
  16. const float YZ_PLANE_QUAT_F[4] = {-0.5,-0.5,-0.5,0.5};
  17. const float CANONICAL_VIEW_QUAT_F[][4] =
  18. {
  19. { 0, 0, 0, 1},
  20. { 0, 0, SQRT_2_OVER_2, SQRT_2_OVER_2},
  21. { 0, 0, 1, 0},
  22. { 0, 0, SQRT_2_OVER_2,-SQRT_2_OVER_2},
  23. { 0, -1, 0, 0},
  24. {-SQRT_2_OVER_2, SQRT_2_OVER_2, 0, 0},
  25. { -1, 0, 0, 0},
  26. {-SQRT_2_OVER_2,-SQRT_2_OVER_2, 0, 0},
  27. { -0.5, -0.5, -0.5, 0.5},
  28. { 0,-SQRT_2_OVER_2, 0, SQRT_2_OVER_2},
  29. { 0.5, -0.5, 0.5, 0.5},
  30. { SQRT_2_OVER_2, 0, SQRT_2_OVER_2, 0},
  31. { SQRT_2_OVER_2, 0,-SQRT_2_OVER_2, 0},
  32. { 0.5, 0.5, -0.5, 0.5},
  33. { 0, SQRT_2_OVER_2, 0, SQRT_2_OVER_2},
  34. { -0.5, 0.5, 0.5, 0.5},
  35. { 0, SQRT_2_OVER_2, SQRT_2_OVER_2, 0},
  36. { -0.5, 0.5, 0.5, -0.5},
  37. {-SQRT_2_OVER_2, 0, 0,-SQRT_2_OVER_2},
  38. { -0.5, -0.5, -0.5, -0.5},
  39. {-SQRT_2_OVER_2, 0, 0, SQRT_2_OVER_2},
  40. { -0.5, -0.5, 0.5, 0.5},
  41. { 0,-SQRT_2_OVER_2, SQRT_2_OVER_2, 0},
  42. { 0.5, -0.5, 0.5, -0.5}
  43. };
  44. const size_t NUM_CANONICAL_VIEW_QUAT_F = 24;
  45. # undef SQRT_2_OVER_2
  46. # define SQRT_2_OVER_2 0.707106781186548f
  47. // Double versions
  48. // Identity
  49. const double IDENTITY_QUAT_D[4] = {0,0,0,1};
  50. // The following match the Matlab canonical views
  51. // X point right, Y pointing up and Z point out
  52. const double XY_PLANE_QUAT_D[4] = {0,0,0,1};
  53. // X points right, Y points *in* and Z points up
  54. const double XZ_PLANE_QUAT_D[4] = {-SQRT_2_OVER_2,0,0,SQRT_2_OVER_2};
  55. // X points out, Y points right, and Z points up
  56. const double YZ_PLANE_QUAT_D[4] = {-0.5,-0.5,-0.5,0.5};
  57. const double CANONICAL_VIEW_QUAT_D[][4] =
  58. {
  59. { 0, 0, 0, 1},
  60. { 0, 0, SQRT_2_OVER_2, SQRT_2_OVER_2},
  61. { 0, 0, 1, 0},
  62. { 0, 0, SQRT_2_OVER_2,-SQRT_2_OVER_2},
  63. { 0, -1, 0, 0},
  64. {-SQRT_2_OVER_2, SQRT_2_OVER_2, 0, 0},
  65. { -1, 0, 0, 0},
  66. {-SQRT_2_OVER_2,-SQRT_2_OVER_2, 0, 0},
  67. { -0.5, -0.5, -0.5, 0.5},
  68. { 0,-SQRT_2_OVER_2, 0, SQRT_2_OVER_2},
  69. { 0.5, -0.5, 0.5, 0.5},
  70. { SQRT_2_OVER_2, 0, SQRT_2_OVER_2, 0},
  71. { SQRT_2_OVER_2, 0,-SQRT_2_OVER_2, 0},
  72. { 0.5, 0.5, -0.5, 0.5},
  73. { 0, SQRT_2_OVER_2, 0, SQRT_2_OVER_2},
  74. { -0.5, 0.5, 0.5, 0.5},
  75. { 0, SQRT_2_OVER_2, SQRT_2_OVER_2, 0},
  76. { -0.5, 0.5, 0.5, -0.5},
  77. {-SQRT_2_OVER_2, 0, 0,-SQRT_2_OVER_2},
  78. { -0.5, -0.5, -0.5, -0.5},
  79. {-SQRT_2_OVER_2, 0, 0, SQRT_2_OVER_2},
  80. { -0.5, -0.5, 0.5, 0.5},
  81. { 0,-SQRT_2_OVER_2, SQRT_2_OVER_2, 0},
  82. { 0.5, -0.5, 0.5, -0.5}
  83. };
  84. const size_t NUM_CANONICAL_VIEW_QUAT_D = 24;
  85. # undef SQRT_2_OVER_2
  86. }