Vector4.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8" />
  5. <base href="../../../" />
  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. <p class="desc">Class representing a 4D [link:https://en.wikipedia.org/wiki/Vector_space vector].
  12. A 4D vector is an ordered quadruplet of numbers (labeled x, y, z, and w), which can be used to
  13. represent a number of things, such as:
  14. </p>
  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)` 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. <p>
  30. There are other things a 4D vector can be used to represent, however these are the most common uses in *three.js*.
  31. </p>
  32. <p>
  33. Iterating through a [name] instance will yield its components `(x, y, z, w)` in the corresponding order.
  34. </p>
  35. <h2>Code Example</h2>
  36. <code>
  37. const a = new THREE.Vector4( 0, 1, 0, 0 );
  38. //no arguments; will be initialised to (0, 0, 0, 1)
  39. const b = new THREE.Vector4( );
  40. const d = a.dot( b );
  41. </code>
  42. <h2>Constructor</h2>
  43. <h3>[name]( [param:Float x], [param:Float y], [param:Float z], [param:Float w] )</h3>
  44. <p>
  45. [page:Float x] - the x value of this vector. Default is `0`.<br />
  46. [page:Float y] - the y value of this vector. Default is `0`.<br />
  47. [page:Float z] - the z value of this vector. Default is `0`.<br />
  48. [page:Float w] - the w value of this vector. Default is `1`.<br /><br />
  49. Creates a new [name].
  50. </p>
  51. <h2>Properties</h2>
  52. <h3>[property:Boolean isVector4]</h3>
  53. <p>
  54. Read-only flag to check if a given object is of type [name].
  55. </p>
  56. <h3>[property:Float x]</h3>
  57. <h3>[property:Float y]</h3>
  58. <h3>[property:Float z]</h3>
  59. <h3>[property:Float w]</h3>
  60. <h3>[property:Float width]</h3>
  61. <p>Alias for [page:.z z].</p>
  62. <h3>[property:Float height]</h3>
  63. <p>Alias for [page:.w w].</p>
  64. <h2>Methods</h2>
  65. <h3>[method:this add]( [param:Vector4 v] )</h3>
  66. <p>Adds [page:Vector4 v] to this vector.</p>
  67. <h3>[method:this addScalar]( [param:Float s] )</h3>
  68. <p>Adds the scalar value s to this vector's [page:.x x], [page:.y y], [page:.z z] and [page:.w w] values.</p>
  69. <h3>[method:this addScaledVector]( [param:Vector4 v], [param:Float s] )</h3>
  70. <p>Adds the multiple of [page:Vector4 v] and [page:Float s] to this vector.</p>
  71. <h3>[method:this addVectors]( [param:Vector4 a], [param:Vector4 b] )</h3>
  72. <p>Sets this vector to [page:Vector4 a] + [page:Vector4 b].</p>
  73. <h3>[method:this applyMatrix4]( [param:Matrix4 m] )</h3>
  74. <p>
  75. Multiplies this vector by 4 x 4 [page:Matrix4 m].
  76. </p>
  77. <h3>[method:this ceil]()</h3>
  78. <p>
  79. The [page:.x x], [page:.y y], [page:.z z] and [page:.w w] components of this vector are rounded up to the nearest integer value.
  80. </p>
  81. <h3>[method:this clamp]( [param:Vector4 min], [param:Vector4 max] )</h3>
  82. <p>
  83. [page:Vector4 min] - the minimum [page:.x x], [page:.y y], [page:.z z] and [page:.w w] values.<br />
  84. [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 />
  85. 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 />
  86. 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.
  87. </p>
  88. <h3>[method:this clampLength]( [param:Float min], [param:Float max] )</h3>
  89. <p>
  90. [page:Float min] - the minimum value the length will be clamped to <br />
  91. [page:Float max] - the maximum value the length will be clamped to<br /><br />
  92. If this vector's length is greater than the max value, it is replaced by the max value. <br /><br />
  93. If this vector's length is less than the min value, it is replaced by the min value.
  94. </p>
  95. <h3>[method:this clampScalar]( [param:Float min], [param:Float max] )</h3>
  96. <p>
  97. [page:Float min] - the minimum value the components will be clamped to <br />
  98. [page:Float max] - the maximum value the components will be clamped to<br /><br />
  99. 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 />
  100. If this vector's x, y, z or w values are less than the min value, they are replaced by the min value.
  101. </p>
  102. <h3>[method:Vector4 clone]()</h3>
  103. <p>
  104. Returns a new Vector4 with the same [page:.x x], [page:.y y], [page:.z z] and [page:.w w] values as this one.
  105. </p>
  106. <h3>[method:this copy]( [param:Vector4 v] )</h3>
  107. <p>
  108. Copies the values of the passed Vector4's [page:.x x], [page:.y y], [page:.z z] and [page:.w w]
  109. properties to this Vector4.
  110. </p>
  111. <h3>[method:this divideScalar]( [param:Float s] )</h3>
  112. <p>
  113. Divides this vector by scalar [page:Float s].
  114. </p>
  115. <h3>[method:Float dot]( [param:Vector4 v] )</h3>
  116. <p>
  117. Calculates the [link:https://en.wikipedia.org/wiki/Dot_product dot product] of this
  118. vector and [page:Vector4 v].
  119. </p>
  120. <h3>[method:Boolean equals]( [param:Vector4 v] )</h3>
  121. <p>Returns `true` if the components of this vector and [page:Vector4 v] are strictly equal; `false` otherwise.</p>
  122. <h3>[method:this floor]()</h3>
  123. <p>The components of this vector are rounded down to the nearest integer value.</p>
  124. <h3>[method:this fromArray]( [param:Array array], [param:Integer offset] )</h3>
  125. <p>
  126. [page:Array array] - the source array.<br />
  127. [page:Integer offset] - (optional) offset into the array. Default is 0.<br /><br />
  128. Sets this vector's [page:.x x] value to be `array[ offset + 0 ]`, [page:.y y] value to be `array[ offset + 1 ]`
  129. [page:.z z] value to be `array[ offset + 2 ]` and [page:.w w ] value to be `array[ offset + 3 ]`.
  130. </p>
  131. <h3>[method:this fromBufferAttribute]( [param:BufferAttribute attribute], [param:Integer index] )</h3>
  132. <p>
  133. [page:BufferAttribute attribute] - the source attribute.<br />
  134. [page:Integer index] - index in the attribute.<br /><br />
  135. Sets this vector's [page:.x x], [page:.y y], [page:.z z] and [page:.w w] values from the [page:BufferAttribute attribute].
  136. </p>
  137. <h3>[method:Float getComponent]( [param:Integer index] )</h3>
  138. <p>
  139. [page:Integer index] - 0, 1, 2 or 3.<br /><br />
  140. If index equals 0 returns the [page:.x x] value. <br />
  141. If index equals 1 returns the [page:.y y] value. <br />
  142. If index equals 2 returns the [page:.z z] value.<br />
  143. If index equals 3 returns the [page:.w w] value.
  144. </p>
  145. <h3>[method:Float length]()</h3>
  146. <p>Computes the [link:https://en.wikipedia.org/wiki/Euclidean_distance Euclidean length]
  147. (straight-line length) from `(0, 0, 0, 0)` to `(x, y, z, w)`.</p>
  148. <h3>[method:Float manhattanLength]()</h3>
  149. <p>
  150. Computes the [link:http://en.wikipedia.org/wiki/Taxicab_geometry Manhattan length] of this vector.
  151. </p>
  152. <h3>[method:Float lengthSq]()</h3>
  153. <p>
  154. Computes the square of the [link:https://en.wikipedia.org/wiki/Euclidean_distance Euclidean length]
  155. (straight-line length) from `(0, 0, 0, 0)` to `(x, y, z, w)`. If you are comparing the lengths of
  156. vectors, you should compare the length squared instead as it is slightly more efficient to calculate.
  157. </p>
  158. <h3>[method:this lerp]( [param:Vector4 v], [param:Float alpha] )</h3>
  159. <p>
  160. [page:Vector4 v] - [page:Vector4] to interpolate towards.<br />
  161. [page:Float alpha] - interpolation factor, typically in the closed interval `[0, 1]`.<br /><br />
  162. Linearly interpolates between this vector and [page:Vector4 v], where alpha is the
  163. percent distance along the line - `alpha = 0` will be this vector, and `alpha = 1` will be [page:Vector4 v].
  164. </p>
  165. <h3>[method:this lerpVectors]( [param:Vector4 v1], [param:Vector4 v2], [param:Float alpha] )</h3>
  166. <p>
  167. [page:Vector4 v1] - the starting [page:Vector4].<br />
  168. [page:Vector4 v2] - [page:Vector4] to interpolate towards.<br />
  169. [page:Float alpha] - interpolation factor, typically in the closed interval `[0, 1]`.<br /><br />
  170. Sets this vector to be the vector linearly interpolated between [page:Vector4 v1] and
  171. [page:Vector4 v2] where alpha is the percent distance along the line connecting the two vectors
  172. - alpha = 0 will be [page:Vector4 v1], and alpha = 1 will be [page:Vector4 v2].
  173. </p>
  174. <h3>[method:this negate]()</h3>
  175. <p>Inverts this vector - i.e. sets x = -x, y = -y, z = -z and w = -w.</p>
  176. <h3>[method:this normalize]()</h3>
  177. <p>
  178. Converts this vector to a [link:https://en.wikipedia.org/wiki/Unit_vector unit vector] - that is, sets it equal to a vector with the same direction
  179. as this one, but [page:.length length] 1.
  180. </p>
  181. <h3>[method:this max]( [param:Vector4 v] )</h3>
  182. <p>
  183. If this vector's x, y, z or w value is less than [page:Vector4 v]'s x, y, z or w value, replace
  184. that value with the corresponding max value.
  185. </p>
  186. <h3>[method:this min]( [param:Vector4 v] )</h3>
  187. <p>
  188. If this vector's x, y, z or w value is greater than [page:Vector4 v]'s x, y, z or w value, replace
  189. that value with the corresponding min value.
  190. </p>
  191. <h3>[method:this multiply]( [param:Vector4 v] )</h3>
  192. <p>Multiplies this vector by [page:Vector4 v].</p>
  193. <h3>[method:this multiplyScalar]( [param:Float s] )</h3>
  194. <p>Multiplies this vector by scalar [page:Float s].</p>
  195. <h3>[method:this round]()</h3>
  196. <p>The components of this vector are rounded to the nearest integer value.</p>
  197. <h3>[method:this roundToZero]()</h3>
  198. <p>
  199. The components of this vector are rounded towards zero (up if negative, down if positive) to an integer value.
  200. </p>
  201. <h3>[method:this set]( [param:Float x], [param:Float y], [param:Float z], [param:Float w] )</h3>
  202. <p>Sets the [page:.x x], [page:.y y], [page:.z z] and [page:.w w] components of this vector.</p>
  203. <h3>[method:this setAxisAngleFromQuaternion]( [param:Quaternion q] )</h3>
  204. <p>
  205. [page:Quaternion q] - a normalized [page:Quaternion]<br /><br />
  206. Sets the [page:.x x], [page:.y y] and [page:.z z] components of this vector to the
  207. quaternion's axis and [page:.w w] to the angle.
  208. </p>
  209. <h3>[method:this setAxisAngleFromRotationMatrix]( [param:Matrix4 m] )</h3>
  210. <p>
  211. [page:Matrix4 m] - a [page:Matrix4] of which the upper left 3x3 matrix is a pure rotation matrix.<br /><br />
  212. Sets the [page:.x x], [page:.y y] and [page:.z z] to the axis of rotation and [page:.w w] to the angle.
  213. </p>
  214. <h3>[method:this setComponent]( [param:Integer index], [param:Float value] )</h3>
  215. <p>
  216. [page:Integer index] - 0, 1 or 2.<br />
  217. [page:Float value] - [page:Float]<br /><br />
  218. If index equals 0 set [page:.x x] to [page:Float value].<br />
  219. If index equals 1 set [page:.y y] to [page:Float value].<br />
  220. If index equals 2 set [page:.z z] to [page:Float value].<br />
  221. If index equals 3 set [page:.w w] to [page:Float value].
  222. </p>
  223. <h3>[method:this setLength]( [param:Float l] )</h3>
  224. <p>
  225. Sets this vector to a vector with the same direction as this one, but [page:.length length]
  226. [page:Float l].
  227. </p>
  228. <h3>[method:this setScalar]( [param:Float scalar] )</h3>
  229. <p>
  230. Sets the [page:.x x], [page:.y y], [page:.z z] and [page:.w w] values of this vector both equal to [page:Float scalar].
  231. </p>
  232. <h3>[method:this setX]( [param:Float x] )</h3>
  233. <p>Replaces this vector's [page:.x x] value with [page:Float x].</p>
  234. <h3>[method:this setY]( [param:Float y] )</h3>
  235. <p>Replaces this vector's [page:.y y] value with [page:Float y].</p>
  236. <h3>[method:this setZ]( [param:Float z] )</h3>
  237. <p>Replaces this vector's [page:.z z] value with [page:Float z].</p>
  238. <h3>[method:this setW]( [param:Float w] )</h3>
  239. <p>Replaces this vector's [page:.w w] value with [page:Float w].</p>
  240. <h3>[method:this sub]( [param:Vector4 v] )</h3>
  241. <p>Subtracts [page:Vector4 v] from this vector.</p>
  242. <h3>[method:this subScalar]( [param:Float s] )</h3>
  243. <p>Subtracts [page:Float s] from this vector's [page:.x x], [page:.y y], [page:.z z] and [page:.w w] components.</p>
  244. <h3>[method:this subVectors]( [param:Vector4 a], [param:Vector4 b] )</h3>
  245. <p>Sets this vector to [page:Vector4 a] - [page:Vector4 b].</p>
  246. <h3>[method:Array toArray]( [param:Array array], [param:Integer offset] )</h3>
  247. <p>
  248. [page:Array array] - (optional) array to store this vector to. If this is not provided, a new array will be created.<br />
  249. [page:Integer offset] - (optional) optional offset into the array.<br /><br />
  250. Returns an array [x, y, z, w], or copies x, y, z and w into the provided [page:Array array].
  251. </p>
  252. <h3>[method:this random]()</h3>
  253. <p>
  254. Sets each component of this vector to a pseudo-random value between 0 and 1, excluding 1.
  255. </p>
  256. <h2>Source</h2>
  257. <p>
  258. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  259. </p>
  260. </body>
  261. </html>