Vector3.html 12 KB

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