Vector3.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  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">3D vector.</div>
  12. <h2>Example</h2>
  13. <code>var a = new THREE.Vector3( 1, 0, 0 );
  14. var b = new THREE.Vector3( 0, 1, 0 );
  15. var c = new THREE.Vector3();
  16. c.crossVectors( a, b );
  17. </code>
  18. <h2>Constructor</h2>
  19. <h3>[name]( [page:Float x], [page:Float y], [page:Float z] )</h3>
  20. <div>
  21. x -- [page:Float] the vector's x value <br />
  22. y -- [page:Float] the vector's y value <br />
  23. z -- [page:Float] the vector's z value
  24. </div>
  25. <div>
  26. A 3 dimensional vector
  27. </div>
  28. <h2>Properties</h2>
  29. <h3>.[page:Float x]</h3>
  30. <h3>.[page:Float y]</h3>
  31. <h3>.[page:Float z]</h3>
  32. <h2>Methods</h2>
  33. <h3>.set( [page:Float x], [page:Float y], [page:Float z] ) [page:Vector3 this]</h3>
  34. <div>
  35. Sets value of this vector.
  36. </div>
  37. <h3>.setX( [page:Float x] ) [page:Vector3 this]</h3>
  38. <div>
  39. Sets x value of this vector.
  40. </div>
  41. <h3>.setY( [page:Float y] ) [page:Vector3 this]</h3>
  42. <div>
  43. Sets y value of this vector.
  44. </div>
  45. <h3>.setZ( [page:Float z] ) [page:Vector3 this]</h3>
  46. <div>
  47. Sets z value of this vector.
  48. </div>
  49. <h3>.copy( [page:Vector3 v] ) [page:Vector3 this]</h3>
  50. <div>
  51. Copies value of *v* to this vector.
  52. </div>
  53. <h3>.add( [page:Vector3 v] ) [page:Vector3 this]</h3>
  54. <div>
  55. Adds *v* to this vector.
  56. </div>
  57. <h3>.addVectors( [page:Vector3 a], [page:Vector3 b] ) [page:Vector3 this]</h3>
  58. <div>
  59. Sets this vector to *a + b*.
  60. </div>
  61. <h3>.sub( [page:Vector3 v] ) [page:Vector3 this]</h3>
  62. <div>
  63. Subtracts *v* from this vector.
  64. </div>
  65. <h3>.subVectors( [page:Vector3 a], [page:Vector3 b] ) [page:Vector3 this]</h3>
  66. <div>
  67. Sets this vector to *a - b*.
  68. </div>
  69. <h3>.multiplyScalar( [page:Float s] ) [page:Vector3 this]</h3>
  70. <div>
  71. Multiplies this vector by scalar *s*.
  72. </div>
  73. <h3>.divideScalar( [page:Float s] ) [page:Vector3 this]</h3>
  74. <div>
  75. Divides this vector by scalar *s*.<br />
  76. Set vector to *( 0, 0, 0 )* if *s == 0*.
  77. </div>
  78. <h3>.negate() [page:Vector3 this]</h3>
  79. <div>
  80. Inverts this vector.
  81. </div>
  82. <h3>.dot( [page:Vector3 v] ) [page:Float]</h3>
  83. <div>
  84. Computes dot product of this vector and *v*.
  85. </div>
  86. <h3>.lengthSq() [page:Float]</h3>
  87. <div>
  88. Computes squared length of this vector.
  89. </div>
  90. <h3>.length() [page:Float]</h3>
  91. <div>
  92. Computes length of this vector.
  93. </div>
  94. <h3>.lengthManhattan() [page:Float]</h3>
  95. <div>
  96. Computes Manhattan length of this vector.<br />
  97. [link:http://en.wikipedia.org/wiki/Taxicab_geometry]
  98. </div>
  99. <h3>.normalize() [page:Vector3 this]</h3>
  100. <div>
  101. Normalizes this vector. Transforms this Vector into a Unit vector by dividing the vector by it's length.
  102. </div>
  103. <h3>.distanceTo( [page:Vector3 v] ) [page:Float]</h3>
  104. <div>
  105. Computes distance of this vector to *v*.
  106. </div>
  107. <h3>.distanceToSquared( [page:Vector3 v] ) [page:Float]</h3>
  108. <div>
  109. Computes squared distance of this vector to *v*.
  110. </div>
  111. <h3>.setLength( [page:Float l] ) [page:Vector3 this]</h3>
  112. <div>
  113. Normalizes this vector and multiplies it by *l*.
  114. </div>
  115. <h3>.cross( [page:Vector3 v] ) [page:Vector3 this]</h3>
  116. <div>
  117. Sets this vector to cross product of itself and *v*.
  118. </div>
  119. <h3>.crossVectors( [page:Vector3 a], [page:Vector3 b] ) [page:Vector3 this]</h3>
  120. <div>
  121. Sets this vector to cross product of *a* and *b*.
  122. </div>
  123. <h3>.setFromMatrixPosition( [page:Matrix4 m] ) [page:Vector3 this]</h3>
  124. <div>
  125. Sets this vector extracting position from matrix transform.
  126. </div>
  127. <h3>.setFromMatrixScale( [page:Matrix4 m] ) [page:Vector3 this]</h3>
  128. <div>
  129. Sets this vector extracting scale from matrix transform.
  130. </div>
  131. <h3>.equals( [page:Vector3 v] ) [page:Boolean]</h3>
  132. <div>
  133. Checks for strict equality of this vector and *v*.
  134. </div>
  135. <h3>.clone() [page:Vector3]</h3>
  136. <div>
  137. Clones this vector.
  138. </div>
  139. <h3>.clamp([page:Vector3 min], [page:Vector3 max]) [page:Vector3 this]</h3>
  140. <div>
  141. min -- [page:Vector3] <br />
  142. max -- [page:Vector3]
  143. </div>
  144. <div>
  145. If this vector's x, y or z value is greater than the max vector's x, y or z value, it is replaced by the corresponding value. <br /><br />
  146. If this vector's x, y or z value is less than the min vector's x, y or z value, it is replace by the corresponding value.
  147. </div>
  148. <h3>.clampScalar([page:Float min], [page:Float max]) [page:Vector3 this]</h3>
  149. <div>
  150. min -- [page:Float] the minimum value the components will be clamped to <br />
  151. max -- [page:Float] the maximum value the components will be clamped to
  152. </div>
  153. <div>
  154. If this vector's x, y or z values are greater than the max value, they are replaced by the max value. <br /> If this vector's x, y or z values are less than the min value, they are replace by the min value.
  155. </div>
  156. <h3>.floor() [page:Vector3]</h3>
  157. <div>
  158. The components of the vector are rounded downwards (towards negative infinity) to an integer value.
  159. </div>
  160. <h3>.ceil() [page:Vector3]</h3>
  161. <div>
  162. The components of the vector are rounded upwards (towards positive infinity) to an integer value.
  163. </div>
  164. <h3>.round() [page:Vector3]</h3>
  165. <div>
  166. The components of the vector are rounded towards the nearest integer value.
  167. </div>
  168. <h3>.roundToZero() [page:Vector3]</h3>
  169. <div>
  170. The components of the vector are rounded towards zero (up if negative, down if positive) to an integer value.
  171. </div>
  172. <h3>.applyMatrix3([page:Matrix3 m]) [page:Vector3 this]</h3>
  173. <div>
  174. m -- [page:Matrix3]
  175. </div>
  176. <div>
  177. Multiplies this vector times a 3 x 3 matrix.
  178. </div>
  179. <h3>.applyMatrix4([page:Matrix3 m]) [page:Vector3 this]</h3>
  180. <div>
  181. m -- [page:Matrix4]
  182. </div>
  183. <div>
  184. Multiplies this vector by 4 x 3 subset of a Matrix4.
  185. </div>
  186. <h3>.projectOnPlane([page:Vector3 planeNormal]) [page:Vector3 this]</h3>
  187. <div>
  188. planeNormal -- [page:Vector3 planeNormal] A vector representing a plane normal.
  189. </div>
  190. <div>
  191. Projects this vector onto a plane by subtracting this vector projected onto the plane's normal from this vector.
  192. </div>
  193. <h3>.projectOnVector([page:Vector3]) [page:Vector3 this]</h3>
  194. <div>
  195. vector -- [page:Vector3]
  196. </div>
  197. <div>
  198. Projects this vector onto another vector.
  199. </div>
  200. <h3>.addScalar([page:Float]) [page:Vector3 this]</h3>
  201. <div>
  202. s -- [page:Float]
  203. </div>
  204. <div>
  205. Adds a s to this vector.
  206. </div>
  207. <h3>.divide([page:Vector3 v]) [page:Vector3 this]</h3>
  208. <div>
  209. v -- [page:Vector3]
  210. </div>
  211. <div>
  212. Divides this vector by vector v.
  213. </div>
  214. <h3>.min([page:Vector3 v]) [page:Vector3 this]</h3>
  215. <div>
  216. v -- [page:Vector3]
  217. </div>
  218. <div>
  219. If this vector's x, y, or z value is less than vector v's x, y, or z value, that value is replaced by the corresponding vector v value.
  220. </div>
  221. <h3>.max([page:Vector3 v]) [page:Vector3 this]</h3>
  222. <div>
  223. v -- [page:Vector3]
  224. </div>
  225. <div>
  226. If this vector's x, y, or z value is greater than vector v's x, y, or z value, that value is replaced by the corresponding vector v value.
  227. </div>
  228. <h3>.setComponent([page:Integer index], [page:Float value]) [page:Vector3 this]</h3>
  229. <div>
  230. index -- 0, 1, or 2 <br />
  231. value -- [page:Float]
  232. </div>
  233. <div>
  234. If index equals 0 the method sets this vector's x value to value <br />
  235. If index equals 1 the method sets this vector's y value to value <br />
  236. If index equals 2 the method sets this vector's z value to value
  237. </div>
  238. <h3>.transformDirection([page:Matrix4 m]) [page:Vector3 this]</h3>
  239. <div>
  240. m -- [page:Matrix4]
  241. </div>
  242. <div>
  243. Transforms the direction of this vector by a matrix (a 3 x 3 subset of a Matrix4) and then normalizes the result.
  244. </div>
  245. <h3>.multiplyVectors([page:Vector3 a], [page:Vector3 b]) [page:Vector3 this]</h3>
  246. <div>
  247. a -- [page:Vector3] <br />
  248. b -- [page:Vector3]
  249. </div>
  250. <div>
  251. Sets this vector equal to the result of multiplying vector a by vector b.
  252. </div>
  253. <h3>.getComponent([page:Integer index]) [page:Float]</h3>
  254. <div>
  255. index -- [page:Integer] 0, 1, or 2
  256. </div>
  257. <div>
  258. Returns the value of the vector component x, y, or z by an index. <br /><br />
  259. Index 0: x <br />
  260. Index 1: y <br />
  261. Index 2: z <br />
  262. </div>
  263. <h3>.applyAxisAngle([page:Vector3 axis], [page:Float angle]) [page:Vector3 this]</h3>
  264. <div>
  265. axis -- A normalized [page:Vector3] <br />
  266. angle -- An angle in radians
  267. </div>
  268. <div>
  269. Applies a rotation specified by an axis and an angle to this vector.
  270. </div>
  271. <h3>.lerp([page:Vector3 v], [page:Float alpha]) [page:Vector3 this]</h3>
  272. <div>
  273. v -- [page:Vector3] <br />
  274. alpha -- [page:Float] between 0 and 1.
  275. </div>
  276. <div>
  277. Linear Interpolation between this vector and vector v, where alpha is the percent along the line.
  278. </div>
  279. <h3>.angleTo([page:Vector3 v]) [page:Float]</h3>
  280. <div>
  281. v -- [page:Vector3]
  282. </div>
  283. <div>
  284. Returns the angle between this vector and vector v in radians.
  285. </div>
  286. <h3>.setFromMatrixColumn([page:Integer index], [page:Matrix4 matrix]) [page:Vector3 this]</h3>
  287. <div>
  288. index -- 0, 1, 2, or 3 <br />
  289. matrix -- [page:Matrix4]
  290. </div>
  291. <div>
  292. Sets this vector's x, y, and z equal to the column of the matrix specified by the index.
  293. </div>
  294. <h3>.reflect([page:Vector3 normal]) [page:Vector3 this]</h3>
  295. <div>
  296. normal -- [page:Vector3] the normal to the reflecting plane
  297. </div>
  298. <div>
  299. Reflect incident vector off of plane orthogonal to normal. normal is assumed to have unit length.
  300. </div>
  301. <h3>.fromArray([page:Array array]) [page:Vector3 this]</h3>
  302. <div>
  303. array -- [page:Array] [x, y, z]
  304. </div>
  305. <div>
  306. Sets the vector's components based on an array formatted like [x, y, z]
  307. </div>
  308. <h3>.multiply([page:Vector3 v]) [page:Vector3 this]</h3>
  309. <div>
  310. v -- [page:Vector3] <br />
  311. </div>
  312. <div>
  313. Multipies this vector by vector v.
  314. </div>
  315. <h3>.applyProjection([page:Matrix4 m]) [page:Vector3 this]</h3>
  316. <div>
  317. m -- [page:Matrix4] projection matrix.
  318. </div>
  319. <div>
  320. Multiplies this vector and m, and divides by perspective.
  321. </div>
  322. <h3>.toArray() [page:Array]</h3>
  323. <div>
  324. Assigns this vector's x value to array[0]. <br />
  325. Assigns this vector's y value to array[1]. <br />
  326. Assigns this vector's z value to array[2]. <br />
  327. Returns the created array.
  328. </div>
  329. <h3>.applyEuler([page:Euler euler]) [page:Vector3 this]</h3>
  330. <div>
  331. euler -- [page:Euler]
  332. </div>
  333. <div>
  334. Applies euler transform to this vector by converting the [page:Euler] obect to a [page:Quaternion] and applying.
  335. </div>
  336. <h3>.applyQuaternion([page:Quaternion quaternion]) [page:Vector3 this]</h3>
  337. <div>
  338. quaternion -- [page:Quaternion]
  339. </div>
  340. <div>
  341. Applies a [page:Quaternion] transform to this vector.
  342. </div>
  343. <h3>.project( [page:Camera camera] ) [page:Vector3]</h3>
  344. <div>
  345. [page:Camera camera] — camera to use in the projection.<br />
  346. </div>
  347. <div>
  348. Projects the vector with the camera.
  349. </div>
  350. <h3>.unproject( [page:Camera camera] ) [page:Vector3]</h3>
  351. <div>
  352. [page:Camera camera] — camera to use in the projection.<br />
  353. </div>
  354. <div>
  355. Unprojects the vector with the camera.
  356. </div>
  357. <h2>Source</h2>
  358. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  359. </body>
  360. </html>