Vector3.rst 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. Vector3 - 3D vector
  2. -------------------
  3. .. ...............................................................................
  4. .. rubric:: Constructor
  5. .. ...............................................................................
  6. .. class:: Vector3()
  7. 3D vector
  8. :param float x: x-coordinate
  9. :param float y: y-coordinate
  10. :param float z: z-coordinate
  11. .. ...............................................................................
  12. .. rubric:: Attributes
  13. .. ...............................................................................
  14. .. attribute:: Vector3.x
  15. float - default ``0``
  16. .. attribute:: Vector3.y
  17. float - default ``0``
  18. .. attribute:: Vector3.z
  19. float - default ``0``
  20. .. ...............................................................................
  21. .. rubric:: Methods
  22. .. ...............................................................................
  23. .. function:: Vector3.clone( )
  24. Clones this vector
  25. :returns: New instance identical to this vector
  26. :rtype: :class:`Vector3`
  27. .. function:: Vector3.set( x, y, z )
  28. Sets value of this vector
  29. :param float x: x-coordinate
  30. :param float y: y-coordinate
  31. :param float z: z-coordinate
  32. :returns: This vector
  33. :rtype: :class:`Vector3`
  34. .. function:: Vector3.setX( x )
  35. Sets x-value of this vector
  36. :param float x: x-coordinate
  37. :returns: This vector
  38. :rtype: :class:`Vector3`
  39. .. function:: Vector3.setY( y )
  40. Sets y-value of this vector
  41. :param float y: y-coordinate
  42. :returns: This vector
  43. :rtype: :class:`Vector3`
  44. .. function:: Vector3.setZ( z )
  45. Sets z-value of this vector
  46. :param float z: z-coordinate
  47. :returns: This vector
  48. :rtype: :class:`Vector3`
  49. .. function:: Vector3.copy( v )
  50. Copies value of ``v`` to this vector
  51. :param Vector3 v: source vector
  52. :returns: This vector
  53. :rtype: :class:`Vector3`
  54. .. function:: Vector3.add( v1, v2 )
  55. Sets this vector to ``v1 + v2``
  56. :param Vector3 v1: source vector 1
  57. :param Vector3 v2: source vector 2
  58. :returns: This vector
  59. :rtype: :class:`Vector3`
  60. .. function:: Vector3.addSelf( v )
  61. Adds ``v`` to this vector
  62. :param Vector3 v: source vector
  63. :returns: This vector
  64. :rtype: :class:`Vector3`
  65. .. function:: Vector3.sub( v1, v2 )
  66. Sets this vector to ``v1 - v2``
  67. :param Vector3 v1: source vector 1
  68. :param Vector3 v2: source vector 2
  69. .. function:: Vector3.subSelf( v )
  70. Subtracts ``v`` from this vector
  71. :param Vector3 v: source vector
  72. :returns: This vector
  73. :rtype: :class:`Vector3`
  74. .. function:: Vector3.multiplyScalar( s )
  75. Multiplies this vector by scalar ``s``
  76. :param float s: scalar
  77. :returns: This vector
  78. :rtype: :class:`Vector3`
  79. .. function:: Vector3.divideScalar( s )
  80. Divides this vector by scalar ``s``
  81. Set vector to ``( 0, 0, 0 )`` if ``s == 0``
  82. :param float s: scalar
  83. :returns: This vector
  84. :rtype: :class:`Vector3`
  85. .. function:: Vector3.negate( )
  86. Inverts this vector
  87. :returns: This vector
  88. :rtype: :class:`Vector3`
  89. .. function:: Vector3.dot( v )
  90. Computes dot product of this vector and ``v``
  91. :param Vector3 v: vector
  92. :returns: dot product
  93. :rtype: float
  94. .. function:: Vector3.lengthSq( )
  95. Computes squared length of this vector
  96. :returns: squared length
  97. :rtype: float
  98. .. function:: Vector3.length( )
  99. Computes length of this vector
  100. :returns: length
  101. :rtype: float
  102. .. function:: Vector3.lengthManhattan( )
  103. Computes Manhattan length of this vector
  104. http://en.wikipedia.org/wiki/Taxicab_geometry
  105. :returns: length
  106. :rtype: float
  107. .. function:: Vector3.normalize( )
  108. Normalizes this vector
  109. :returns: This vector
  110. :rtype: :class:`Vector3`
  111. .. function:: Vector3.distanceTo( v )
  112. Computes distance of this vector to ``v``
  113. :param Vector3 v: vector
  114. :returns: squared distance
  115. :rtype: float
  116. .. function:: Vector3.distanceToSquared( v )
  117. Computes squared distance of this vector to ``v``
  118. :param Vector3 v: vector
  119. :returns: squared distance
  120. :rtype: float
  121. .. function:: Vector3.setLength( l )
  122. Normalizes this vector and multiplies it by ``l``
  123. :returns: This vector
  124. :rtype: :class:`Vector3`
  125. .. function:: Vector3.cross( a, b )
  126. Sets this vector to cross product of ``a`` and ``b``
  127. :param Vector3 a: vector
  128. :param Vector3 b: vector
  129. :returns: This vector
  130. :rtype: :class:`Vector3`
  131. .. function:: Vector3.crossSelf( v )
  132. Sets this vector to cross product of itself and ``v``
  133. :param Vector3 v: vector
  134. :returns: This vector
  135. :rtype: :class:`Vector3`
  136. .. function:: Vector3.setPositionFromMatrix( m )
  137. Sets this vector extracting position from matrix transform
  138. :param Matrix4 m: matrix
  139. :returns: This vector
  140. :rtype: :class:`Vector3`
  141. .. function:: Vector3.setRotationFromMatrix( m )
  142. Sets this vector extracting Euler angles rotation from matrix transform
  143. :param Matrix4 m: matrix
  144. :returns: This vector
  145. :rtype: :class:`Vector3`
  146. .. function:: Vector3.equals( v )
  147. Checks for strict equality of this vector and ``v``
  148. :param Vector3 v: vector
  149. :returns: true if this vector equals ``v``
  150. :rtype: boolean
  151. .. function:: Vector3.isZero( )
  152. Checks if length of this vector is within small epsilon (``0.0001``)
  153. :returns: true if this vector is zero
  154. :rtype: boolean
  155. .. ...............................................................................
  156. .. rubric:: Example
  157. .. ...............................................................................
  158. ::
  159. var a = new THREE.Vector3( 1, 0, 0 );
  160. var b = new THREE.Vector3( 0, 1, 0 );
  161. var c = new THREE.Vector3();
  162. c.cross( a, b );