Vector4.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  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">Class representing a 4D [link:https://en.wikipedia.org/wiki/Vector_space vector].
  13. A 4D vector is an ordered quadruplet of numbers (labeled x, y, z, and w), which can be used to
  14. represent a number of things, such as:
  15. <ul>
  16. <li>
  17. A point in 4D space.
  18. </li>
  19. <li>
  20. A direction and length in 4D space. In three.js the length will always be the
  21. [link:https://en.wikipedia.org/wiki/Euclidean_distance Euclidean distance]
  22. (straight-line distance) from (0, 0, 0, 0, 0) to (x, y, z, w) and the direction is also
  23. measured from (0, 0, 0, 0) towards (x, y, z, w).
  24. </li>
  25. <li>
  26. Any arbitrary ordered quadruplet of numbers.
  27. </li>
  28. </ul>
  29. There are other things a 4D vector can be used to represent, however these are the most common uses in three.js.
  30. </div>
  31. <h2>Example</h2>
  32. <code>
  33. var a = new THREE.Vector4( 0, 1, 0, 0 );
  34. //no arguments; will be initialised to (0, 0, 0, 1)
  35. var b = new THREE.Vector4( );
  36. var d = a.distanceTo( b );
  37. </code>
  38. <h2>Constructor</h2>
  39. <h3>[name]( [page:Float x], [page:Float y], [page:Float z], [page:Float w] )</h3>
  40. <div>
  41. [page:Float x] - the x value of the vector. Default is *0*.<br />
  42. [page:Float y] - the y value of the vector. Default is *0*.<br />
  43. [page:Float z] - the z value of the vector. Default is *0*.<br />
  44. [page:Float w] - the w value of the vector. Default is *1*.<br /><br />
  45. Creates a new [name].
  46. </div>
  47. <h2>Properties</h2>
  48. <h3>[property:Boolean isVector4]</h3>
  49. <div>
  50. Used to check whether this or derived classes are Vector4s. Default is *true*.<br /><br />
  51. You should not change this, as it used internally for optimisation.
  52. </div>
  53. <h3>[property:Float x]</h3>
  54. <h3>[property:Float y]</h3>
  55. <h3>[property:Float z]</h3>
  56. <h3>[property:Float w]</h3>
  57. <h2>Methods</h2>
  58. <h3>[method:Vector4 add]( [page:Vector4 v] )</h3>
  59. <div>Adds [page:Vector4 v] to this vector.</div>
  60. <h3>[method:Vector4 addScalar]( [page:Float s] )</h3>
  61. <div>Add the scalar value s to this vector's [page:.x x], [page:.y y], [page:.z z] and [page:.w w] values.</div>
  62. <h3>[method:Vector4 addScaledVector]( [page:Vector4 v], [page:Float s] )</h3>
  63. <div>Adds the multiple of [page:Vector4 v] and [page:Float s] to this vector.</div>
  64. <h3>[method:Vector4 addVectors]( [page:Vector4 a], [page:Vector4 b] )</h3>
  65. <div>Sets this vector to [page:Vector4 a] + [page:Vector4 b].</div>
  66. <h3>[method:Vector4 applyMatrix4]( [page:Matrix4 m] )</h3>
  67. <div>
  68. Multiply this vector by 4 x 4 [page:Matrix4 m].
  69. </div>
  70. <h3>[method:Vector4 ceil]()</h3>
  71. <div>
  72. The [page:.x x], [page:.y y], [page:.z z] and [page:.w w] components of the vector are rounded up to the nearest integer value.
  73. </div>
  74. <h3>[method:Vector4 clamp]( [page:Vector4 min], [page:Vector4 max] )</h3>
  75. <div>
  76. [page:Vector4 min] - the minimum [page:.x x], [page:.y y], [page:.z z] and [page:.w w] values.<br />
  77. [page:Vector4 max] - the maximum [page:.x x], [page:.y y], [page:.z z] and [page:.w w] values in the desired range<br /><br />
  78. If this vector's x, y, z or w value is greater than the max vector's x, y, z or w value, it is replaced by the corresponding value. <br /><br />
  79. If this vector's x, y, z or w value is less than the min vector's x, y, z or w value, it is replaced by the corresponding value.
  80. </div>
  81. <h3>[method:Vector4 clampScalar]( [page:Float min], [page:Float max] )</h3>
  82. <div>
  83. [page:Float min] - the minimum value the components will be clamped to <br />
  84. [page:Float max] - the maximum value the components will be clamped to<br /><br />
  85. If this vector's x, y, z or w values are greater than the max value, they are replaced by the max value. <br /><br />
  86. If this vector's x, y, z or w values are less than the min value, they are replaced by the min value.
  87. </div>
  88. <h3>[method:Vector4 clone]()</h3>
  89. <div>
  90. Returns a new Vector4 with the same [page:.x x], [page:.y y], [page:.z z] and [page:.w w] values as this one.
  91. </div>
  92. <h3>[method:Vector4 copy]( [page:Vector4 v] )</h3>
  93. <div>
  94. Copies the values of the passed Vector4's [page:.x x], [page:.y y], [page:.z z] and [page:.w w]
  95. properties to this Vector4.
  96. </div>
  97. <h3>[method:Vector4 divideScalar]( [page:Float s] )</h3>
  98. <div>
  99. Divides this vector by scalar [page:Float s].<br />
  100. Sets vector to *( 0, 0 )* if *[page:Float s] = 0*.
  101. </div>
  102. <h3>[method:Float dot]( [page:Vector4 v] )</h3>
  103. <div>
  104. Calculate the [link:https://en.wikipedia.org/wiki/Dot_product dot product] of this
  105. vector and [page:Vector4 v].
  106. </div>
  107. <h3>[method:Boolean equals]( [page:Vector4 v] )</h3>
  108. <div>Checks for strict equality of this vector and [page:Vector4 v].</div>
  109. <h3>[method:Vector4 floor]()</h3>
  110. <div>The components of the vector are rounded down to the nearest integer value.</div>
  111. <h3>[method:Vector4 fromArray]( [page:Array array], [page:Integer offset] )</h3>
  112. <div>
  113. [page:Array array] - the source array.<br />
  114. [page:Integer offset] - ( optional) offset into the array. Default is 0.<br /><br />
  115. Sets this vector's [page:.x x] value to be array[ offset + 0 ], [page:.y y] value to be array[ offset + 1 ]
  116. [page:.z z] value to be array[ offset + 2 ] and [page:.w w ] value to be array[ offset + 3 ].
  117. </div>
  118. <h3>[method:Vector4 fromBufferAttribute]( [page:BufferAttribute attribute], [page:Integer index] )</h3>
  119. <div>
  120. [page:BufferAttribute attribute] - the source attribute.<br />
  121. [page:Integer index] - index in the attribute.<br /><br />
  122. Sets this vector's [page:.x x], [page:.y y], [page:.z z] and [page:.w w] values from the [page:BufferAttribute attribute].
  123. </div>
  124. <h3>[method:Float getComponent]( [page:Integer index] )</h3>
  125. <div>
  126. [page:Integer index] - 0, 1 or 2.<br /><br />
  127. If index equals 0 returns the [page:.x x] value. <br />
  128. If index equals 1 returns the [page:.y y] value. <br />
  129. If index equals 2 returns the [page:.z z] value.<br />
  130. If index equals 3 returns the [page:.w w] value.
  131. </div>
  132. <h3>[method:Float length]()</h3>
  133. <div>Computes the [link:https://en.wikipedia.org/wiki/Euclidean_distance Euclidean length]
  134. (straight-line length) from (0, 0, 0, 0) to (x, y, z, w).</div>
  135. <h3>[method:Float lengthManhattan]()</h3>
  136. <div>
  137. Computes the [link:http://en.wikipedia.org/wiki/Taxicab_geometry Manhattan length] of this vector.
  138. </div>
  139. <h3>[method:Float lengthSq]()</h3>
  140. <div>
  141. Computes the square of the [link:https://en.wikipedia.org/wiki/Euclidean_distance Euclidean length]
  142. (straight-line length) from (0, 0, 0, 0) to (x, y, z, w). If you are comparing the lengths of
  143. vectors, you should compare the length squared instead as it is slightly more efficient to calculate.
  144. </div>
  145. <h3>[method:Vector4 lerp]( [page:Vector4 v], [page:Float alpha] )</h3>
  146. <div>
  147. [page:Vector4 v] - [page:Vector4] to interpolate towards.<br />
  148. alpha - interpolation factor in the closed interval [0, 1].<br /><br />
  149. Linearly interpolate between this vector and [page:Vector4 v], where alpha is the
  150. distance along the line - alpha = 0 will be this vector, and alpha = 1 will be [page:Vector4 v].
  151. </div>
  152. <h3>[method:Vector4 lerpVectors]( [page:Vector4 v1], [page:Vector4 v2], [page:Float alpha] )</h3>
  153. <div>
  154. [page:Vector4 v1] - the starting [page:Vector4].<br />
  155. [page:Vector4 v2] - [page:Vector4] to interpolate towards.<br />
  156. [page:Float alpha] - interpolation factor in the closed interval [0, 1].<br /><br />
  157. Sets this vector to be the vector linearly interpolated between [page:Vector4 v1] and
  158. [page:Vector4 v2] where alpha is the distance along the line connecting the two vectors
  159. - alpha = 0 will be [page:Vector4 v1], and alpha = 1 will be [page:Vector4 v2].
  160. </div>
  161. <h3>[method:Vector4 negate]()</h3>
  162. <div>Inverts this vector - i.e. sets x = -x, y = -y, z = -z and w = -w.</div>
  163. <h3>[method:Vector4 normalize]()</h3>
  164. <div>
  165. Convert this vector to a [link:https://en.wikipedia.org/wiki/Unit_vector unit vector] - that is, sets it equal to the vector with the same direction
  166. as this one, but [page:.length length] 1.
  167. </div>
  168. <h3>[method:Vector4 max]( [page:Vector4 v] )</h3>
  169. <div>
  170. If this vector's x, y, z or w value is less than [page:Vector4 v's] x, y, z or w value, replace
  171. that value with the corresponding max value.
  172. </div>
  173. <h3>[method:Vector4 min]( [page:Vector4 v] )</h3>
  174. <div>
  175. If this vector's x, y, z or w value is greater than [page:Vector4 v's] x, y, z or w value, replace
  176. that value with the corresponding min value.
  177. </div>
  178. <h3>[method:Vector4 multiplyScalar]( [page:Float s] )</h3>
  179. <div>Multiplies this vector by scalar [page:Float s].</div>
  180. <h3>[method:Vector4 round]()</h3>
  181. <div>The components of the vector are rounded to the nearest integer value.</div>
  182. <h3>[method:Vector4 roundToZero]()</h3>
  183. <div>
  184. The components of the vector are rounded towards zero (up if negative, down if positive) to an integer value.
  185. </div>
  186. <h3>[method:Vector4 set]( [page:Float x], [page:Float y], [page:Float z], [page:Float w] )</h3>
  187. <div>Sets the [page:.x x], [page:.y y], [page:.z z] and [page:.w w] components of this vector.</div>
  188. <h3>[method:Vector4 setAxisAngleFromQuaternion]( [page:Quaterion q] )</h3>
  189. <div>
  190. [page:Quaterion q] - a normalized [page:Quaterion]<br /><br />
  191. Set the [page:.x x], [page:.y y] and [page:.z z] components of this vector to the
  192. quaternion's axis and [page:.w w] to the angle.
  193. </div>
  194. <h3>[method:Vector4 setAxisAngleFromRotationMatrix]( [page:Matrix4 m] )</h3>
  195. <div>
  196. [page:Matrix4 m] - a [page:Matrix4] of which the upper left 3x3 matrix is a pure rotation matrix.<br /><br />
  197. Set the [page:.x x], [page:.y y] and [page:.z z] to the axis of rotation and [page:.w w] to the angle.
  198. </div>
  199. <h3>[method:null setComponent]( [page:Integer index], [page:Float value] )</h3>
  200. <div>
  201. [page:Integer index] - 0, 1 or 2.<br />
  202. [page:Float value] - [page:Float]<br /><br />
  203. If index equals 0 set [page:.x x] to [page:Float value].<br />
  204. If index equals 1 set [page:.y y] to [page:Float value].<br />
  205. If index equals 2 set [page:.z z] to [page:Float value].<br />
  206. If index equals 3 set [page:.w w] to [page:Float value].
  207. </div>
  208. <h3>[method:Vector4 setLength]( [page:Float l] )</h3>
  209. <div>
  210. Set this vector to the vector with the same direction as this one, but [page:.length length]
  211. [page:Float l].
  212. </div>
  213. <h3>[method:Vector4 setScalar]( [page:Float scalar] )</h3>
  214. <div>
  215. Set the [page:.x x], [page:.y y], [page:.z z] and [page:.w w] values of this vector both equal to [page:Float scalar].
  216. </div>
  217. <h3>[method:Vector4 setX]( [page:Float x] )</h3>
  218. <div>Replace this vector's [page:.x x] value with [page:Float x].</div>
  219. <h3>[method:Vector4 setY]( [page:Float y] )</h3>
  220. <div>Replace this vector's [page:.y y] value with [page:Float y].</div>
  221. <h3>[method:Vector4 setZ]( [page:Float z] )</h3>
  222. <div>Replace this vector's [page:.z z] value with [page:Float z].</div>
  223. <h3>[method:Vector4 setW]( [page:Float w] )</h3>
  224. <div>Replace this vector's [page:.w w] value with [page:Float w].</div>
  225. <h3>[method:Vector4 sub]( [page:Vector4 v] )</h3>
  226. <div>Subtracts [page:Vector4 v] from this vector.</div>
  227. <h3>[method:Vector4 subScalar]( [page:Float s] )</h3>
  228. <div>Subtracts [page:Float s] from this vector's [page:.x x], [page:.y y], [page:.z z] and [page:.w w] compnents.</div>
  229. <h3>[method:Vector4 subVectors]( [page:Vector4 a], [page:Vector4 b] )</h3>
  230. <div>Sets this vector to [page:Vector4 a] - [page:Vector4 b].</div>
  231. <h3>[method:Array toArray]( [page:Array array], [page:Integer offset] )</h3>
  232. <div>
  233. [page:Array array] - (optional) array to store the vector to. If this is not provided
  234. a new array will be created.<br />
  235. [page:Integer offset] - (optional) optional offset into the array.<br /><br />
  236. Returns an array [x, y, z, w], or copies x, y, z and w into the provided [page:Array array].
  237. </div>
  238. <h2>Source</h2>
  239. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  240. </body>
  241. </html>