Quaternion.html 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8" />
  5. <script src="../../list.js"></script>
  6. <script src="../../page.js"></script>
  7. <link type="text/css" rel="stylesheet" href="../../page.css" />
  8. </head>
  9. <body>
  10. <h1>[name]</h1>
  11. <div class="desc">Implementation of a <a href="http://en.wikipedia.org/wiki/Quaternion">quaternion</a>. This is used for rotating things without encountering the dreaded <a href="http://en.wikipedia.org/wiki/Gimbal_lock">gimbal lock</a> issue, amongst other advantages.</div>
  12. <h2>Example</h2>
  13. <code>var quaternion = new THREE.Quaternion();
  14. quaternion.setFromAxisAngle( new THREE.Vector3( 0, 1, 0 ), Math.PI / 2 );
  15. var vector = new THREE.Vector3( 1, 0, 0 );
  16. vector.applyQuaternion( quaternion );
  17. </code>
  18. <h2>Constructor</h2>
  19. <h3>[name]( [page:Float x], [page:Float y], [page:Float z], [page:Float w] )</h3>
  20. <div>
  21. x - x coordinate<br />
  22. y - y coordinate<br />
  23. z - z coordinate<br />
  24. w - w coordinate
  25. </div>
  26. <h2>Properties</h2>
  27. <h3>[property:Float x]</h3>
  28. <h3>[property:Float y]</h3>
  29. <h3>[property:Float z]</h3>
  30. <h3>[property:Float w]</h3>
  31. <h2>Methods</h2>
  32. <h3>[method:Quaternion set]( [page:Float x], [page:Float y], [page:Float z], [page:Float w] )</h3>
  33. <div>
  34. Sets values of this quaternion.
  35. </div>
  36. <h3>[method:Quaternion copy]( [page:Quaternion q] )</h3>
  37. <div>
  38. Copies values of *q* to this quaternion.
  39. </div>
  40. <h3>[method:Quaternion setFromEuler]( [page:Euler euler] )</h3>
  41. <div>
  42. Sets this quaternion from rotation specified by Euler angle.
  43. </div>
  44. <h3>[method:Quaternion setFromAxisAngle]( [page:Vector3 axis], [page:Float angle] )</h3>
  45. <div>
  46. Sets this quaternion from rotation specified by axis and angle.<br />
  47. Adapted from [link:http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm].<br />
  48. *Axis* is asumed to be normalized, *angle* is in radians.
  49. </div>
  50. <h3>[method:Quaternion setFromRotationMatrix]( [page:Matrix4 m] )</h3>
  51. <div>
  52. Sets this quaternion from rotation component of *m*.<br />
  53. Adapted from [link:http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm].
  54. </div>
  55. <h3>[method:Quaternion setFromUnitVectors]( [page:Vector3 vFrom], [page:Vector3 vTo] )</h3>
  56. <div>
  57. Sets this quaternion to the rotation required to rotate direction vector *vFrom* to direction vector *vTo*.<br />
  58. Adapted from [link:http://lolengine.net/blog/2013/09/18/beautiful-maths-quaternion-from-vectors].<br />
  59. *vFrom* and *vTo* are assumed to be normalized.
  60. </div>
  61. <h3>[method:Quaternion inverse]()</h3>
  62. <div>
  63. Inverts this quaternion.
  64. </div>
  65. <h3>[method:Float length]()</h3>
  66. <div>
  67. Computes length of this quaternion.
  68. </div>
  69. <h3>[method:Quaternion normalize]()</h3>
  70. <div>
  71. Normalizes this quaternion.
  72. </div>
  73. <h3>[method:Quaternion multiply]( [page:Quaternion b] )</h3>
  74. <div>
  75. Multiplies this quaternion by *b*.
  76. </div>
  77. <h3>[method:Quaternion multiplyQuaternions]( [page:Quaternion a], [page:Quaternion b] )</h3>
  78. <div>
  79. Sets this quaternion to *a x b*<br />
  80. Adapted from [link:http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm].
  81. </div>
  82. <h3>[method:Quaternion multiplyVector3]( [page:Vector3 vector], [page:Vector3 dest] )</h3>
  83. <div>
  84. Rotates *vector* by this quaternion into *dest*.<br />
  85. If *dest* is not specified, result goes to *vec*.
  86. </div>
  87. <h3>[method:Quaternion clone]()</h3>
  88. <div>
  89. Clones this quaternion.
  90. </div>
  91. <h2>Static methods</h2>
  92. <h3>[method:Quaternion slerp]( [page:Quaternion qa], [page:Quaternion qb], [page:Quaternion qm], [page:Float t] )</h3>
  93. <div>
  94. Adapted from [link:http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/].
  95. </div>
  96. <h3>[method:Quaternion slerp]([page:Quaternion qb], [page:float t])</h3>
  97. <div>
  98. qb -- Target quaternion rotation.<br />
  99. t -- Normalized [0..1] interpolation factor.
  100. </div>
  101. <div>
  102. Handles the spherical linear interpolation between this quaternion's configuration
  103. and that of *qb*. *t* represents how close to the current (0) or target (1) rotation the
  104. result should be.
  105. </div>
  106. <h3>.toArray() [page: Array]</h3>
  107. <div>
  108. Returns the numerical elements of this quaternion in an array of format (x, y, z, w).
  109. </div>
  110. <h3>[method:Boolean equals]([page:Quaternion v])</h3>
  111. <div>
  112. v -- Quaternion that this quaternion will be compared to.
  113. </div>
  114. <div>
  115. Compares each component of *v* to each component of this quaternion to determine if they
  116. represent the same rotation.
  117. </div>
  118. <h3>[method:Float lengthSq]()</h3>
  119. <div>
  120. Calculates the squared length of the quaternion.
  121. </div>
  122. <h3>[method:Quaternion fromArray]([page:Array array])</h3>
  123. <div>
  124. array -- Array of format (x, y, z, w) used to construct the quaternion.
  125. </div>
  126. <div>
  127. Sets this quaternion's component values from an array.
  128. </div>
  129. <h3>[method:Quaternion conjugate]()</h3>
  130. <div>
  131. Returns the rotational conjugate of this quaternion. The conjugate of a quaternion
  132. represents the same rotation in the opposite direction about the rotational axis.
  133. </div>
  134. <h2>Source</h2>
  135. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  136. </body>
  137. </html>