Quaternion.html 5.3 KB

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