class_vector2.rst 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  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. Properties
  12. ----------
  13. +---------------------------+------------------------------------+
  14. | :ref:`float<class_float>` | :ref:`x<class_Vector2_property_x>` |
  15. +---------------------------+------------------------------------+
  16. | :ref:`float<class_float>` | :ref:`y<class_Vector2_property_y>` |
  17. +---------------------------+------------------------------------+
  18. Methods
  19. -------
  20. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  21. | :ref:`Vector2<class_Vector2>` | :ref:`Vector2<class_Vector2_method_Vector2>` **(** :ref:`float<class_float>` x, :ref:`float<class_float>` y **)** |
  22. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  23. | :ref:`Vector2<class_Vector2>` | :ref:`abs<class_Vector2_method_abs>` **(** **)** |
  24. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  25. | :ref:`float<class_float>` | :ref:`angle<class_Vector2_method_angle>` **(** **)** |
  26. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  27. | :ref:`float<class_float>` | :ref:`angle_to<class_Vector2_method_angle_to>` **(** :ref:`Vector2<class_Vector2>` to **)** |
  28. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  29. | :ref:`float<class_float>` | :ref:`angle_to_point<class_Vector2_method_angle_to_point>` **(** :ref:`Vector2<class_Vector2>` to **)** |
  30. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  31. | :ref:`float<class_float>` | :ref:`aspect<class_Vector2_method_aspect>` **(** **)** |
  32. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  33. | :ref:`Vector2<class_Vector2>` | :ref:`bounce<class_Vector2_method_bounce>` **(** :ref:`Vector2<class_Vector2>` n **)** |
  34. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  35. | :ref:`Vector2<class_Vector2>` | :ref:`ceil<class_Vector2_method_ceil>` **(** **)** |
  36. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  37. | :ref:`Vector2<class_Vector2>` | :ref:`clamped<class_Vector2_method_clamped>` **(** :ref:`float<class_float>` length **)** |
  38. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  39. | :ref:`float<class_float>` | :ref:`cross<class_Vector2_method_cross>` **(** :ref:`Vector2<class_Vector2>` with **)** |
  40. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  41. | :ref:`Vector2<class_Vector2>` | :ref:`cubic_interpolate<class_Vector2_method_cubic_interpolate>` **(** :ref:`Vector2<class_Vector2>` b, :ref:`Vector2<class_Vector2>` pre_a, :ref:`Vector2<class_Vector2>` post_b, :ref:`float<class_float>` t **)** |
  42. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  43. | :ref:`Vector2<class_Vector2>` | :ref:`direction_to<class_Vector2_method_direction_to>` **(** :ref:`Vector2<class_Vector2>` b **)** |
  44. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  45. | :ref:`float<class_float>` | :ref:`distance_squared_to<class_Vector2_method_distance_squared_to>` **(** :ref:`Vector2<class_Vector2>` to **)** |
  46. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  47. | :ref:`float<class_float>` | :ref:`distance_to<class_Vector2_method_distance_to>` **(** :ref:`Vector2<class_Vector2>` to **)** |
  48. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  49. | :ref:`float<class_float>` | :ref:`dot<class_Vector2_method_dot>` **(** :ref:`Vector2<class_Vector2>` with **)** |
  50. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  51. | :ref:`Vector2<class_Vector2>` | :ref:`floor<class_Vector2_method_floor>` **(** **)** |
  52. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  53. | :ref:`bool<class_bool>` | :ref:`is_normalized<class_Vector2_method_is_normalized>` **(** **)** |
  54. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  55. | :ref:`float<class_float>` | :ref:`length<class_Vector2_method_length>` **(** **)** |
  56. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  57. | :ref:`float<class_float>` | :ref:`length_squared<class_Vector2_method_length_squared>` **(** **)** |
  58. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  59. | :ref:`Vector2<class_Vector2>` | :ref:`linear_interpolate<class_Vector2_method_linear_interpolate>` **(** :ref:`Vector2<class_Vector2>` b, :ref:`float<class_float>` t **)** |
  60. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  61. | :ref:`Vector2<class_Vector2>` | :ref:`move_toward<class_Vector2_method_move_toward>` **(** :ref:`Vector2<class_Vector2>` to, :ref:`float<class_float>` delta **)** |
  62. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  63. | :ref:`Vector2<class_Vector2>` | :ref:`normalized<class_Vector2_method_normalized>` **(** **)** |
  64. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  65. | :ref:`Vector2<class_Vector2>` | :ref:`project<class_Vector2_method_project>` **(** :ref:`Vector2<class_Vector2>` b **)** |
  66. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  67. | :ref:`Vector2<class_Vector2>` | :ref:`reflect<class_Vector2_method_reflect>` **(** :ref:`Vector2<class_Vector2>` n **)** |
  68. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  69. | :ref:`Vector2<class_Vector2>` | :ref:`rotated<class_Vector2_method_rotated>` **(** :ref:`float<class_float>` phi **)** |
  70. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  71. | :ref:`Vector2<class_Vector2>` | :ref:`round<class_Vector2_method_round>` **(** **)** |
  72. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  73. | :ref:`Vector2<class_Vector2>` | :ref:`slerp<class_Vector2_method_slerp>` **(** :ref:`Vector2<class_Vector2>` b, :ref:`float<class_float>` t **)** |
  74. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  75. | :ref:`Vector2<class_Vector2>` | :ref:`slide<class_Vector2_method_slide>` **(** :ref:`Vector2<class_Vector2>` n **)** |
  76. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  77. | :ref:`Vector2<class_Vector2>` | :ref:`snapped<class_Vector2_method_snapped>` **(** :ref:`Vector2<class_Vector2>` by **)** |
  78. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  79. | :ref:`Vector2<class_Vector2>` | :ref:`tangent<class_Vector2_method_tangent>` **(** **)** |
  80. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  81. Constants
  82. ---------
  83. .. _class_Vector2_constant_ZERO:
  84. .. _class_Vector2_constant_ONE:
  85. .. _class_Vector2_constant_INF:
  86. .. _class_Vector2_constant_LEFT:
  87. .. _class_Vector2_constant_RIGHT:
  88. .. _class_Vector2_constant_UP:
  89. .. _class_Vector2_constant_DOWN:
  90. - **ZERO** = **Vector2( 0, 0 )** --- Zero vector.
  91. - **ONE** = **Vector2( 1, 1 )** --- One vector.
  92. - **INF** = **Vector2( inf, inf )** --- Infinite vector.
  93. - **LEFT** = **Vector2( -1, 0 )** --- Left unit vector.
  94. - **RIGHT** = **Vector2( 1, 0 )** --- Right unit vector.
  95. - **UP** = **Vector2( 0, -1 )** --- Up unit vector.
  96. - **DOWN** = **Vector2( 0, 1 )** --- Down unit vector.
  97. Description
  98. -----------
  99. 2-element structure that can be used to represent positions in 2d space or any other pair of numeric values.
  100. Tutorials
  101. ---------
  102. - :doc:`../tutorials/math/index`
  103. Property Descriptions
  104. ---------------------
  105. .. _class_Vector2_property_x:
  106. - :ref:`float<class_float>` **x**
  107. The vector's x component. Also accessible by using the index position ``[0]``.
  108. .. _class_Vector2_property_y:
  109. - :ref:`float<class_float>` **y**
  110. The vector's y component. Also accessible by using the index position ``[1]``.
  111. Method Descriptions
  112. -------------------
  113. .. _class_Vector2_method_Vector2:
  114. - :ref:`Vector2<class_Vector2>` **Vector2** **(** :ref:`float<class_float>` x, :ref:`float<class_float>` y **)**
  115. Constructs a new Vector2 from the given x and y.
  116. .. _class_Vector2_method_abs:
  117. - :ref:`Vector2<class_Vector2>` **abs** **(** **)**
  118. Returns a new vector with all components in absolute values (i.e. positive).
  119. .. _class_Vector2_method_angle:
  120. - :ref:`float<class_float>` **angle** **(** **)**
  121. Returns the vector's angle in radians with respect to the x-axis, or ``(1, 0)`` vector.
  122. Equivalent to the result of atan2 when called with the vector's x and y as parameters: ``atan2(x, y)``.
  123. .. _class_Vector2_method_angle_to:
  124. - :ref:`float<class_float>` **angle_to** **(** :ref:`Vector2<class_Vector2>` to **)**
  125. Returns the angle in radians between the two vectors.
  126. .. _class_Vector2_method_angle_to_point:
  127. - :ref:`float<class_float>` **angle_to_point** **(** :ref:`Vector2<class_Vector2>` to **)**
  128. Returns the angle in radians between the line connecting the two points and the x coordinate.
  129. .. _class_Vector2_method_aspect:
  130. - :ref:`float<class_float>` **aspect** **(** **)**
  131. Returns the ratio of x to y.
  132. .. _class_Vector2_method_bounce:
  133. - :ref:`Vector2<class_Vector2>` **bounce** **(** :ref:`Vector2<class_Vector2>` n **)**
  134. Returns the vector "bounced off" from a plane defined by the given normal.
  135. .. _class_Vector2_method_ceil:
  136. - :ref:`Vector2<class_Vector2>` **ceil** **(** **)**
  137. Returns the vector with all components rounded up.
  138. .. _class_Vector2_method_clamped:
  139. - :ref:`Vector2<class_Vector2>` **clamped** **(** :ref:`float<class_float>` length **)**
  140. Returns the vector with a maximum length.
  141. .. _class_Vector2_method_cross:
  142. - :ref:`float<class_float>` **cross** **(** :ref:`Vector2<class_Vector2>` with **)**
  143. Returns the 2 dimensional analog of the cross product with the given vector.
  144. .. _class_Vector2_method_cubic_interpolate:
  145. - :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 **)**
  146. 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``, representing the amount of interpolation.
  147. .. _class_Vector2_method_direction_to:
  148. - :ref:`Vector2<class_Vector2>` **direction_to** **(** :ref:`Vector2<class_Vector2>` b **)**
  149. Returns the normalized vector pointing from this vector to ``b``.
  150. .. _class_Vector2_method_distance_squared_to:
  151. - :ref:`float<class_float>` **distance_squared_to** **(** :ref:`Vector2<class_Vector2>` to **)**
  152. Returns the squared distance to vector ``b``. Prefer this function over :ref:`distance_to<class_Vector2_method_distance_to>` if you need to sort vectors or need the squared distance for some formula.
  153. .. _class_Vector2_method_distance_to:
  154. - :ref:`float<class_float>` **distance_to** **(** :ref:`Vector2<class_Vector2>` to **)**
  155. Returns the distance to vector ``b``.
  156. .. _class_Vector2_method_dot:
  157. - :ref:`float<class_float>` **dot** **(** :ref:`Vector2<class_Vector2>` with **)**
  158. Returns the dot product with vector ``b``.
  159. .. _class_Vector2_method_floor:
  160. - :ref:`Vector2<class_Vector2>` **floor** **(** **)**
  161. Returns the vector with all components rounded down.
  162. .. _class_Vector2_method_is_normalized:
  163. - :ref:`bool<class_bool>` **is_normalized** **(** **)**
  164. Returns ``true`` if the vector is normalized.
  165. .. _class_Vector2_method_length:
  166. - :ref:`float<class_float>` **length** **(** **)**
  167. Returns the vector's length.
  168. .. _class_Vector2_method_length_squared:
  169. - :ref:`float<class_float>` **length_squared** **(** **)**
  170. Returns the vector's length squared. Prefer this method over :ref:`length<class_Vector2_method_length>` if you need to sort vectors or need the squared length for some formula.
  171. .. _class_Vector2_method_linear_interpolate:
  172. - :ref:`Vector2<class_Vector2>` **linear_interpolate** **(** :ref:`Vector2<class_Vector2>` b, :ref:`float<class_float>` t **)**
  173. 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``, representing the amount of interpolation.
  174. .. _class_Vector2_method_move_toward:
  175. - :ref:`Vector2<class_Vector2>` **move_toward** **(** :ref:`Vector2<class_Vector2>` to, :ref:`float<class_float>` delta **)**
  176. Moves the vector toward ``to`` by the fixed ``delta`` amount.
  177. .. _class_Vector2_method_normalized:
  178. - :ref:`Vector2<class_Vector2>` **normalized** **(** **)**
  179. Returns the vector scaled to unit length. Equivalent to ``v / v.length()``.
  180. .. _class_Vector2_method_project:
  181. - :ref:`Vector2<class_Vector2>` **project** **(** :ref:`Vector2<class_Vector2>` b **)**
  182. Returns the vector projected onto the vector ``b``.
  183. .. _class_Vector2_method_reflect:
  184. - :ref:`Vector2<class_Vector2>` **reflect** **(** :ref:`Vector2<class_Vector2>` n **)**
  185. Returns the vector reflected from a plane defined by the given normal.
  186. .. _class_Vector2_method_rotated:
  187. - :ref:`Vector2<class_Vector2>` **rotated** **(** :ref:`float<class_float>` phi **)**
  188. Returns the vector rotated by ``phi`` radians. See also :ref:`@GDScript.deg2rad<class_@GDScript_method_deg2rad>`.
  189. .. _class_Vector2_method_round:
  190. - :ref:`Vector2<class_Vector2>` **round** **(** **)**
  191. Returns the vector with all components rounded to the nearest integer, with halfway cases rounded away from zero.
  192. .. _class_Vector2_method_slerp:
  193. - :ref:`Vector2<class_Vector2>` **slerp** **(** :ref:`Vector2<class_Vector2>` b, :ref:`float<class_float>` t **)**
  194. Returns the result of SLERP between this vector and ``b``, by amount ``t``. ``t`` is in the range of ``0.0 - 1.0``, representing the amount of interpolation.
  195. Both vectors need to be normalized.
  196. .. _class_Vector2_method_slide:
  197. - :ref:`Vector2<class_Vector2>` **slide** **(** :ref:`Vector2<class_Vector2>` n **)**
  198. Returns the component of the vector along a plane defined by the given normal.
  199. .. _class_Vector2_method_snapped:
  200. - :ref:`Vector2<class_Vector2>` **snapped** **(** :ref:`Vector2<class_Vector2>` by **)**
  201. Returns the vector snapped to a grid with the given size.
  202. .. _class_Vector2_method_tangent:
  203. - :ref:`Vector2<class_Vector2>` **tangent** **(** **)**
  204. Returns a perpendicular vector.