class_vector2.rst 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. .. Generated automatically by doc/tools/makerst.py in Godot's source tree.
  2. .. DO NOT EDIT THIS FILE, but the Vector2.xml source instead.
  3. .. The source is found in doc/classes or modules/<name>/doc_classes.
  4. .. _class_Vector2:
  5. Vector2
  6. =======
  7. **Category:** Built-In Types
  8. Brief Description
  9. -----------------
  10. Vector used for 2D math.
  11. Member Functions
  12. ----------------
  13. +--------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  14. | :ref:`Vector2<class_vector2>` | :ref:`Vector2<class_Vector2_Vector2>` **(** :ref:`float<class_float>` x, :ref:`float<class_float>` y **)** |
  15. +--------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  16. | :ref:`Vector2<class_vector2>` | :ref:`abs<class_Vector2_abs>` **(** **)** |
  17. +--------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  18. | :ref:`float<class_float>` | :ref:`angle<class_Vector2_angle>` **(** **)** |
  19. +--------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  20. | :ref:`float<class_float>` | :ref:`angle_to<class_Vector2_angle_to>` **(** :ref:`Vector2<class_vector2>` to **)** |
  21. +--------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  22. | :ref:`float<class_float>` | :ref:`angle_to_point<class_Vector2_angle_to_point>` **(** :ref:`Vector2<class_vector2>` to **)** |
  23. +--------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  24. | :ref:`float<class_float>` | :ref:`aspect<class_Vector2_aspect>` **(** **)** |
  25. +--------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  26. | :ref:`Vector2<class_vector2>` | :ref:`bounce<class_Vector2_bounce>` **(** :ref:`Vector2<class_vector2>` n **)** |
  27. +--------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  28. | :ref:`Vector2<class_vector2>` | :ref:`ceil<class_Vector2_ceil>` **(** **)** |
  29. +--------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  30. | :ref:`Vector2<class_vector2>` | :ref:`clamped<class_Vector2_clamped>` **(** :ref:`float<class_float>` length **)** |
  31. +--------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  32. | :ref:`float<class_float>` | :ref:`cross<class_Vector2_cross>` **(** :ref:`Vector2<class_vector2>` with **)** |
  33. +--------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  34. | :ref:`Vector2<class_vector2>` | :ref:`cubic_interpolate<class_Vector2_cubic_interpolate>` **(** :ref:`Vector2<class_vector2>` b, :ref:`Vector2<class_vector2>` pre_a, :ref:`Vector2<class_vector2>` post_b, :ref:`float<class_float>` t **)** |
  35. +--------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  36. | :ref:`float<class_float>` | :ref:`distance_squared_to<class_Vector2_distance_squared_to>` **(** :ref:`Vector2<class_vector2>` to **)** |
  37. +--------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  38. | :ref:`float<class_float>` | :ref:`distance_to<class_Vector2_distance_to>` **(** :ref:`Vector2<class_vector2>` to **)** |
  39. +--------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  40. | :ref:`float<class_float>` | :ref:`dot<class_Vector2_dot>` **(** :ref:`Vector2<class_vector2>` with **)** |
  41. +--------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  42. | :ref:`Vector2<class_vector2>` | :ref:`floor<class_Vector2_floor>` **(** **)** |
  43. +--------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  44. | :ref:`bool<class_bool>` | :ref:`is_normalized<class_Vector2_is_normalized>` **(** **)** |
  45. +--------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  46. | :ref:`float<class_float>` | :ref:`length<class_Vector2_length>` **(** **)** |
  47. +--------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  48. | :ref:`float<class_float>` | :ref:`length_squared<class_Vector2_length_squared>` **(** **)** |
  49. +--------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  50. | :ref:`Vector2<class_vector2>` | :ref:`linear_interpolate<class_Vector2_linear_interpolate>` **(** :ref:`Vector2<class_vector2>` b, :ref:`float<class_float>` t **)** |
  51. +--------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  52. | :ref:`Vector2<class_vector2>` | :ref:`normalized<class_Vector2_normalized>` **(** **)** |
  53. +--------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  54. | :ref:`Vector2<class_vector2>` | :ref:`reflect<class_Vector2_reflect>` **(** :ref:`Vector2<class_vector2>` n **)** |
  55. +--------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  56. | :ref:`Vector2<class_vector2>` | :ref:`rotated<class_Vector2_rotated>` **(** :ref:`float<class_float>` phi **)** |
  57. +--------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  58. | :ref:`Vector2<class_vector2>` | :ref:`round<class_Vector2_round>` **(** **)** |
  59. +--------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  60. | :ref:`Vector2<class_vector2>` | :ref:`slerp<class_Vector2_slerp>` **(** :ref:`Vector2<class_vector2>` b, :ref:`float<class_float>` t **)** |
  61. +--------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  62. | :ref:`Vector2<class_vector2>` | :ref:`slide<class_Vector2_slide>` **(** :ref:`Vector2<class_vector2>` n **)** |
  63. +--------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  64. | :ref:`Vector2<class_vector2>` | :ref:`snapped<class_Vector2_snapped>` **(** :ref:`Vector2<class_vector2>` by **)** |
  65. +--------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  66. | :ref:`Vector2<class_vector2>` | :ref:`tangent<class_Vector2_tangent>` **(** **)** |
  67. +--------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  68. Member Variables
  69. ----------------
  70. .. _class_Vector2_x:
  71. - :ref:`float<class_float>` **x** - The vector's x component.
  72. .. _class_Vector2_y:
  73. - :ref:`float<class_float>` **y** - The vector's y component.
  74. Description
  75. -----------
  76. 2-element structure that can be used to represent positions in 2d space or any other pair of numeric values.
  77. Member Function Description
  78. ---------------------------
  79. .. _class_Vector2_Vector2:
  80. - :ref:`Vector2<class_vector2>` **Vector2** **(** :ref:`float<class_float>` x, :ref:`float<class_float>` y **)**
  81. Constructs a new Vector2 from the given x and y.
  82. .. _class_Vector2_abs:
  83. - :ref:`Vector2<class_vector2>` **abs** **(** **)**
  84. Returns a new vector with all components in absolute values (i.e. positive).
  85. .. _class_Vector2_angle:
  86. - :ref:`float<class_float>` **angle** **(** **)**
  87. Returns the vector's angle in radians with respect to the x-axis, or ``(1, 0)`` vector.
  88. Equivalent to the result of atan2 when called with the vector's x and y as parameters: ``atan2(x, y)``.
  89. .. _class_Vector2_angle_to:
  90. - :ref:`float<class_float>` **angle_to** **(** :ref:`Vector2<class_vector2>` to **)**
  91. Returns the angle in radians between the two vectors.
  92. .. _class_Vector2_angle_to_point:
  93. - :ref:`float<class_float>` **angle_to_point** **(** :ref:`Vector2<class_vector2>` to **)**
  94. Returns the angle in radians between the line connecting the two points and the x coordinate.
  95. .. _class_Vector2_aspect:
  96. - :ref:`float<class_float>` **aspect** **(** **)**
  97. Returns the ratio of x to y.
  98. .. _class_Vector2_bounce:
  99. - :ref:`Vector2<class_vector2>` **bounce** **(** :ref:`Vector2<class_vector2>` n **)**
  100. Returns the vector "bounced off" from a plane defined by the given normal.
  101. .. _class_Vector2_ceil:
  102. - :ref:`Vector2<class_vector2>` **ceil** **(** **)**
  103. .. _class_Vector2_clamped:
  104. - :ref:`Vector2<class_vector2>` **clamped** **(** :ref:`float<class_float>` length **)**
  105. Returns the vector with a maximum length.
  106. .. _class_Vector2_cross:
  107. - :ref:`float<class_float>` **cross** **(** :ref:`Vector2<class_vector2>` with **)**
  108. Returns the 2 dimensional analog of the cross product with the given vector.
  109. .. _class_Vector2_cubic_interpolate:
  110. - :ref:`Vector2<class_vector2>` **cubic_interpolate** **(** :ref:`Vector2<class_vector2>` b, :ref:`Vector2<class_vector2>` pre_a, :ref:`Vector2<class_vector2>` post_b, :ref:`float<class_float>` t **)**
  111. Cubicly interpolates between this vector and ``b`` using ``pre_a`` and ``post_b`` as handles, and returns the result at position ``t``. ``t`` is in the range of ``0.0 - 1.0``, or a percentage of how far along the interpolation is.
  112. .. _class_Vector2_distance_squared_to:
  113. - :ref:`float<class_float>` **distance_squared_to** **(** :ref:`Vector2<class_vector2>` to **)**
  114. Returns the squared distance to vector ``b``. Prefer this function over :ref:`distance_to<class_Vector2_distance_to>` if you need to sort vectors or need the squared distance for some formula.
  115. .. _class_Vector2_distance_to:
  116. - :ref:`float<class_float>` **distance_to** **(** :ref:`Vector2<class_vector2>` to **)**
  117. Returns the distance to vector ``b``.
  118. .. _class_Vector2_dot:
  119. - :ref:`float<class_float>` **dot** **(** :ref:`Vector2<class_vector2>` with **)**
  120. Returns the dot product with vector ``b``.
  121. .. _class_Vector2_floor:
  122. - :ref:`Vector2<class_vector2>` **floor** **(** **)**
  123. Remove the fractional part of x and y.
  124. .. _class_Vector2_is_normalized:
  125. - :ref:`bool<class_bool>` **is_normalized** **(** **)**
  126. Returns ``true`` if the vector is normalized.
  127. .. _class_Vector2_length:
  128. - :ref:`float<class_float>` **length** **(** **)**
  129. Returns the vector's length.
  130. .. _class_Vector2_length_squared:
  131. - :ref:`float<class_float>` **length_squared** **(** **)**
  132. Returns the vector's length squared. Prefer this function over :ref:`length<class_Vector2_length>` if you need to sort vectors or need the squared length for some formula.
  133. .. _class_Vector2_linear_interpolate:
  134. - :ref:`Vector2<class_vector2>` **linear_interpolate** **(** :ref:`Vector2<class_vector2>` b, :ref:`float<class_float>` t **)**
  135. Returns the result of the linear interpolation between this vector and ``b`` by amount ``t``. ``t`` is in the range of ``0.0 - 1.0``, a percentage of how far along the interpolation is.
  136. .. _class_Vector2_normalized:
  137. - :ref:`Vector2<class_vector2>` **normalized** **(** **)**
  138. Returns the vector scaled to unit length. Equivalent to ``v / v.length()``.
  139. .. _class_Vector2_reflect:
  140. - :ref:`Vector2<class_vector2>` **reflect** **(** :ref:`Vector2<class_vector2>` n **)**
  141. Returns the vector reflected from a plane defined by the given normal.
  142. .. _class_Vector2_rotated:
  143. - :ref:`Vector2<class_vector2>` **rotated** **(** :ref:`float<class_float>` phi **)**
  144. Returns the vector rotated by ``phi`` radians.
  145. .. _class_Vector2_round:
  146. - :ref:`Vector2<class_vector2>` **round** **(** **)**
  147. .. _class_Vector2_slerp:
  148. - :ref:`Vector2<class_vector2>` **slerp** **(** :ref:`Vector2<class_vector2>` b, :ref:`float<class_float>` t **)**
  149. Returns the result of SLERP between this vector and "b", by amount "t". "t" should be a float of 0.0-1.0, a percentage of how far along the interpolation is.
  150. Both vectors need to be normalized.
  151. .. _class_Vector2_slide:
  152. - :ref:`Vector2<class_vector2>` **slide** **(** :ref:`Vector2<class_vector2>` n **)**
  153. Returns the component of the vector along a plane defined by the given normal.
  154. .. _class_Vector2_snapped:
  155. - :ref:`Vector2<class_vector2>` **snapped** **(** :ref:`Vector2<class_vector2>` by **)**
  156. Returns the vector snapped to a grid with the given size.
  157. .. _class_Vector2_tangent:
  158. - :ref:`Vector2<class_vector2>` **tangent** **(** **)**
  159. Returns a perpendicular vector.