Vector2.rst 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. Vector2 - 2D vector
  2. -------------------
  3. .. ...............................................................................
  4. .. rubric:: Constructor
  5. .. ...............................................................................
  6. .. class:: Vector2( x, y )
  7. 2D vector
  8. :param float x: x-coordinate
  9. :param float y: y-coordinate
  10. .. ...............................................................................
  11. .. rubric:: Attributes
  12. .. ...............................................................................
  13. .. attribute:: Vector2.x
  14. .. attribute:: Vector2.y
  15. .. ...............................................................................
  16. .. rubric:: Methods
  17. .. ...............................................................................
  18. .. function:: Vector2.clone( )
  19. Clones this vector
  20. :returns: New instance identical to this vector
  21. :rtype: :class:`Vector2`
  22. .. function:: Vector2.set( x, y )
  23. Sets value of this vector
  24. :param float x: x-coordinate
  25. :param float y: y-coordinate
  26. :returns: This vector
  27. :rtype: :class:`Vector2`
  28. .. function:: Vector2.copy( v )
  29. Copies value of ``v`` to this vector
  30. :param Vector2 v: source vector
  31. :returns: This vector
  32. :rtype: :class:`Vector2`
  33. .. function:: Vector2.add( v1, v2 )
  34. Sets this vector to ``v1 + v2``
  35. :param Vector2 v1: source vector 1
  36. :param Vector2 v2: source vector 2
  37. :returns: This vector
  38. :rtype: :class:`Vector2`
  39. .. function:: Vector2.addSelf( v )
  40. Adds ``v`` to this vector
  41. :param Vector2 v: source vector
  42. :returns: This vector
  43. :rtype: :class:`Vector2`
  44. .. function:: Vector2.sub( v1, v2 )
  45. Sets this vector to ``v1 - v2``
  46. :param Vector2 v1: source vector 1
  47. :param Vector2 v2: source vector 2
  48. .. function:: Vector2.subSelf( v )
  49. Subtracts ``v`` from this vector
  50. :param Vector2 v: source vector
  51. :returns: This vector
  52. :rtype: :class:`Vector2`
  53. .. function:: Vector2.multiplyScalar( s )
  54. Multiplies this vector by scalar ``s``
  55. :param float s: scalar
  56. :returns: This vector
  57. :rtype: :class:`Vector2`
  58. .. function:: Vector2.divideScalar( s )
  59. Divides this vector by scalar ``s``
  60. Set vector to ``( 0, 0 )`` if ``s == 0``
  61. :param float s: scalar
  62. :returns: This vector
  63. :rtype: :class:`Vector2`
  64. .. function:: Vector2.negate( )
  65. Inverts this vector
  66. :returns: This vector
  67. :rtype: :class:`Vector2`
  68. .. function:: Vector2.dot( v )
  69. Computes dot product of this vector and ``v``
  70. :returns: dot product
  71. :rtype: float
  72. .. function:: Vector2.lengthSq( )
  73. Computes squared length of this vector
  74. :returns: squared length
  75. :rtype: float
  76. .. function:: Vector2.length( )
  77. Computes length of this vector
  78. :returns: length
  79. :rtype: float
  80. .. function:: Vector2.normalize( )
  81. Normalizes this vector
  82. :returns: This vector
  83. :rtype: :class:`Vector2`
  84. .. function:: Vector2.distanceTo( v )
  85. Computes distance of this vector to ``v``
  86. :returns: squared distance
  87. :rtype: float
  88. .. function:: Vector2.distanceToSquared( v )
  89. Computes squared distance of this vector to ``v``
  90. :returns: squared distance
  91. :rtype: float
  92. .. function:: Vector2.setLength( l )
  93. Normalizes this vector and multiplies it by ``l``
  94. :returns: This vector
  95. :rtype: :class:`Vector2`
  96. .. function:: Vector2.equals( v )
  97. Checks for strict equality of this vector and ``v``
  98. :returns: true if this vector equals ``v``
  99. :rtype: boolean
  100. .. function:: Vector2.isZero( )
  101. Checks if length of this vector is within small epsilon (``0.0001``)
  102. :returns: true if this vector is zero
  103. :rtype: boolean
  104. .. ...............................................................................
  105. .. rubric:: Example
  106. .. ...............................................................................
  107. ::
  108. var a = new THREE.Vector2( 0, 1 );
  109. var b = new THREE.Vector2( 1, 0 );
  110. var d = a.distanceTo( b );