Vector2.rst 4.0 KB

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