Vector3.d.ts 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. import { Euler } from './Euler';
  2. import { Matrix3 } from './Matrix3';
  3. import { Matrix4 } from './Matrix4';
  4. import { Quaternion } from './Quaternion';
  5. import { Camera } from './../cameras/Camera';
  6. import { Spherical } from './Spherical';
  7. import { Cylindrical } from './Cylindrical';
  8. import { BufferAttribute } from './../core/BufferAttribute';
  9. import { Vector } from './Vector2';
  10. /**
  11. * 3D vector.
  12. *
  13. * @example
  14. * 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. *
  19. * @see <a href="https://github.com/mrdoob/three.js/blob/master/src/math/Vector3.js">src/math/Vector3.js</a>
  20. *
  21. * ( class Vector3 implements Vector<Vector3> )
  22. */
  23. export class Vector3 implements Vector {
  24. constructor( x?: number, y?: number, z?: number );
  25. x: number;
  26. y: number;
  27. z: number;
  28. readonly isVector3: true;
  29. /**
  30. * Sets value of this vector.
  31. */
  32. set( x: number, y: number, z: number ): this;
  33. /**
  34. * Sets all values of this vector.
  35. */
  36. setScalar( scalar: number ): this;
  37. /**
  38. * Sets x value of this vector.
  39. */
  40. setX( x: number ): Vector3;
  41. /**
  42. * Sets y value of this vector.
  43. */
  44. setY( y: number ): Vector3;
  45. /**
  46. * Sets z value of this vector.
  47. */
  48. setZ( z: number ): Vector3;
  49. setComponent( index: number, value: number ): this;
  50. getComponent( index: number ): number;
  51. /**
  52. * Clones this vector.
  53. */
  54. clone(): this;
  55. /**
  56. * Copies value of v to this vector.
  57. */
  58. copy( v: Vector3 ): this;
  59. /**
  60. * Adds v to this vector.
  61. */
  62. add( v: Vector3, w?: Vector3 ): this;
  63. addScalar( s: number ): this;
  64. addScaledVector( v: Vector3, s: number ): this;
  65. /**
  66. * Sets this vector to a + b.
  67. */
  68. addVectors( a: Vector3, b: Vector3 ): this;
  69. /**
  70. * Subtracts v from this vector.
  71. */
  72. sub( a: Vector3 ): this;
  73. subScalar( s: number ): this;
  74. /**
  75. * Sets this vector to a - b.
  76. */
  77. subVectors( a: Vector3, b: Vector3 ): this;
  78. multiply( v: Vector3 ): this;
  79. /**
  80. * Multiplies this vector by scalar s.
  81. */
  82. multiplyScalar( s: number ): this;
  83. multiplyVectors( a: Vector3, b: Vector3 ): this;
  84. applyEuler( euler: Euler ): this;
  85. applyAxisAngle( axis: Vector3, angle: number ): this;
  86. applyMatrix3( m: Matrix3 ): this;
  87. applyNormalMatrix( m: Matrix3 ): this;
  88. applyMatrix4( m: Matrix4 ): this;
  89. applyQuaternion( q: Quaternion ): this;
  90. project( camera: Camera ): this;
  91. unproject( camera: Camera ): this;
  92. transformDirection( m: Matrix4 ): this;
  93. divide( v: Vector3 ): this;
  94. /**
  95. * Divides this vector by scalar s.
  96. * Set vector to ( 0, 0, 0 ) if s == 0.
  97. */
  98. divideScalar( s: number ): this;
  99. min( v: Vector3 ): this;
  100. max( v: Vector3 ): this;
  101. clamp( min: Vector3, max: Vector3 ): this;
  102. clampScalar( min: number, max: number ): this;
  103. clampLength( min: number, max: number ): this;
  104. floor(): this;
  105. ceil(): this;
  106. round(): this;
  107. roundToZero(): this;
  108. /**
  109. * Inverts this vector.
  110. */
  111. negate(): this;
  112. /**
  113. * Computes dot product of this vector and v.
  114. */
  115. dot( v: Vector3 ): number;
  116. /**
  117. * Computes squared length of this vector.
  118. */
  119. lengthSq(): number;
  120. /**
  121. * Computes length of this vector.
  122. */
  123. length(): number;
  124. /**
  125. * Computes Manhattan length of this vector.
  126. * http://en.wikipedia.org/wiki/Taxicab_geometry
  127. *
  128. * @deprecated Use {@link Vector3#manhattanLength .manhattanLength()} instead.
  129. */
  130. lengthManhattan(): number;
  131. /**
  132. * Computes the Manhattan length of this vector.
  133. *
  134. * @return {number}
  135. *
  136. * @see {@link http://en.wikipedia.org/wiki/Taxicab_geometry|Wikipedia: Taxicab Geometry}
  137. */
  138. manhattanLength(): number;
  139. /**
  140. * Computes the Manhattan length (distance) from this vector to the given vector v
  141. *
  142. * @param {Vector3} v
  143. *
  144. * @return {number}
  145. *
  146. * @see {@link http://en.wikipedia.org/wiki/Taxicab_geometry|Wikipedia: Taxicab Geometry}
  147. */
  148. manhattanDistanceTo( v: Vector3 ): number;
  149. /**
  150. * Normalizes this vector.
  151. */
  152. normalize(): this;
  153. /**
  154. * Normalizes this vector and multiplies it by l.
  155. */
  156. setLength( l: number ): this;
  157. lerp( v: Vector3, alpha: number ): this;
  158. lerpVectors( v1: Vector3, v2: Vector3, alpha: number ): this;
  159. /**
  160. * Sets this vector to cross product of itself and v.
  161. */
  162. cross( a: Vector3, w?: Vector3 ): this;
  163. /**
  164. * Sets this vector to cross product of a and b.
  165. */
  166. crossVectors( a: Vector3, b: Vector3 ): this;
  167. projectOnVector( v: Vector3 ): this;
  168. projectOnPlane( planeNormal: Vector3 ): this;
  169. reflect( vector: Vector3 ): this;
  170. angleTo( v: Vector3 ): number;
  171. /**
  172. * Computes distance of this vector to v.
  173. */
  174. distanceTo( v: Vector3 ): number;
  175. /**
  176. * Computes squared distance of this vector to v.
  177. */
  178. distanceToSquared( v: Vector3 ): number;
  179. /**
  180. * @deprecated Use {@link Vector3#manhattanDistanceTo .manhattanDistanceTo()} instead.
  181. */
  182. distanceToManhattan( v: Vector3 ): number;
  183. setFromSpherical( s: Spherical ): this;
  184. setFromSphericalCoords( r: number, phi: number, theta:number ): this;
  185. setFromCylindrical( s: Cylindrical ): this;
  186. setFromCylindricalCoords( radius: number, theta: number, y: number ): this;
  187. setFromMatrixPosition( m: Matrix4 ): this;
  188. setFromMatrixScale( m: Matrix4 ): this;
  189. setFromMatrixColumn( matrix: Matrix4, index: number ): this;
  190. setFromMatrix3Column( matrix: Matrix3, index: number ): this;
  191. /**
  192. * Checks for strict equality of this vector and v.
  193. */
  194. equals( v: Vector3 ): boolean;
  195. /**
  196. * Sets this vector's x, y and z value from the provided array.
  197. * @param array the source array.
  198. * @param offset (optional) offset into the array. Default is 0.
  199. */
  200. fromArray( array: number[], offset?: number ): this;
  201. /**
  202. * Sets this vector's x, y and z value from the provided array-like.
  203. * @param array the source array-like.
  204. * @param offset (optional) offset into the array-like. Default is 0.
  205. */
  206. fromArray( array: ArrayLike<number>, offset?: number ): this;
  207. /**
  208. * Returns an array [x, y, z], or copies x, y and z into the provided array.
  209. * @param array (optional) array to store the vector to. If this is not provided, a new array will be created.
  210. * @param offset (optional) optional offset into the array.
  211. * @return The created or provided array.
  212. */
  213. toArray( array?: number[], offset?: number ): number[];
  214. /**
  215. * Copies x, y and z into the provided array-like.
  216. * @param array array-like to store the vector to.
  217. * @param offset (optional) optional offset into the array-like.
  218. * @return The provided array-like.
  219. */
  220. toArray( array: ArrayLike<number>, offset?: number ): ArrayLike<number>;
  221. fromBufferAttribute(
  222. attribute: BufferAttribute,
  223. index: number,
  224. offset?: number
  225. ): this;
  226. /**
  227. * Sets this vector's x, y and z from Math.random
  228. */
  229. random(): this;
  230. }