Vector3.html 14 KB

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