class_vector2.rst 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. .. Generated automatically by doc/tools/makerst.py in Godot's source tree.
  2. .. DO NOT EDIT THIS FILE, but the doc/base/classes.xml source instead.
  3. .. _class_Vector2:
  4. Vector2
  5. =======
  6. **Category:** Built-In Types
  7. Brief Description
  8. -----------------
  9. Vector used for 2D Math.
  10. Member Functions
  11. ----------------
  12. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  13. | :ref:`Vector2<class_vector2>` | :ref:`Vector2<class_Vector2_Vector2>` **(** :ref:`float<class_float>` x, :ref:`float<class_float>` y **)** |
  14. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  15. | :ref:`Vector2<class_vector2>` | :ref:`abs<class_Vector2_abs>` **(** **)** |
  16. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  17. | :ref:`float<class_float>` | :ref:`angle<class_Vector2_angle>` **(** **)** |
  18. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  19. | :ref:`float<class_float>` | :ref:`angle_to<class_Vector2_angle_to>` **(** :ref:`Vector2<class_vector2>` to **)** |
  20. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  21. | :ref:`float<class_float>` | :ref:`angle_to_point<class_Vector2_angle_to_point>` **(** :ref:`Vector2<class_vector2>` to **)** |
  22. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  23. | :ref:`Vector2<class_vector2>` | :ref:`clamped<class_Vector2_clamped>` **(** :ref:`float<class_float>` length **)** |
  24. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  25. | :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 **)** |
  26. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  27. | :ref:`float<class_float>` | :ref:`distance_squared_to<class_Vector2_distance_squared_to>` **(** :ref:`Vector2<class_vector2>` to **)** |
  28. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  29. | :ref:`float<class_float>` | :ref:`distance_to<class_Vector2_distance_to>` **(** :ref:`Vector2<class_vector2>` to **)** |
  30. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  31. | :ref:`float<class_float>` | :ref:`dot<class_Vector2_dot>` **(** :ref:`Vector2<class_vector2>` with **)** |
  32. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  33. | :ref:`Vector2<class_vector2>` | :ref:`floor<class_Vector2_floor>` **(** **)** |
  34. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  35. | :ref:`Vector2<class_vector2>` | :ref:`floorf<class_Vector2_floorf>` **(** **)** |
  36. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  37. | :ref:`float<class_float>` | :ref:`get_aspect<class_Vector2_get_aspect>` **(** **)** |
  38. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  39. | :ref:`float<class_float>` | :ref:`length<class_Vector2_length>` **(** **)** |
  40. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  41. | :ref:`float<class_float>` | :ref:`length_squared<class_Vector2_length_squared>` **(** **)** |
  42. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  43. | :ref:`Vector2<class_vector2>` | :ref:`linear_interpolate<class_Vector2_linear_interpolate>` **(** :ref:`Vector2<class_vector2>` b, :ref:`float<class_float>` t **)** |
  44. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  45. | :ref:`Vector2<class_vector2>` | :ref:`normalized<class_Vector2_normalized>` **(** **)** |
  46. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  47. | :ref:`Vector2<class_vector2>` | :ref:`reflect<class_Vector2_reflect>` **(** :ref:`Vector2<class_vector2>` vec **)** |
  48. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  49. | :ref:`Vector2<class_vector2>` | :ref:`rotated<class_Vector2_rotated>` **(** :ref:`float<class_float>` phi **)** |
  50. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  51. | :ref:`Vector2<class_vector2>` | :ref:`slide<class_Vector2_slide>` **(** :ref:`Vector2<class_vector2>` vec **)** |
  52. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  53. | :ref:`Vector2<class_vector2>` | :ref:`snapped<class_Vector2_snapped>` **(** :ref:`Vector2<class_vector2>` by **)** |
  54. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  55. | :ref:`Vector2<class_vector2>` | :ref:`tangent<class_Vector2_tangent>` **(** **)** |
  56. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  57. Member Variables
  58. ----------------
  59. - :ref:`float<class_float>` **height** - Height of the vector (Same as Y).
  60. - :ref:`float<class_float>` **width** - Width of the vector (Same as X).
  61. - :ref:`float<class_float>` **x** - X component of the vector.
  62. - :ref:`float<class_float>` **y** - Y component of the vector.
  63. Description
  64. -----------
  65. 2-element structure that can be used to represent positions in 2d-space, or any other pair of numeric values.
  66. Member Function Description
  67. ---------------------------
  68. .. _class_Vector2_Vector2:
  69. - :ref:`Vector2<class_vector2>` **Vector2** **(** :ref:`float<class_float>` x, :ref:`float<class_float>` y **)**
  70. Constructs a new Vector2 from the given x and y.
  71. .. _class_Vector2_abs:
  72. - :ref:`Vector2<class_vector2>` **abs** **(** **)**
  73. Returns a new vector with all components in absolute values (i.e. positive).
  74. .. _class_Vector2_angle:
  75. - :ref:`float<class_float>` **angle** **(** **)**
  76. Returns the result of atan2 when called with the Vector's x and y as parameters (Math::atan2(x,y)).
  77. Be aware that it therefore returns an angle oriented clockwise with regard to the (0, 1) unit vector, and not an angle oriented counter-clockwise with regard to the (1, 0) unit vector (which would be the typical trigonometric representation of the angle when calling Math::atan2(y,x)).
  78. .. _class_Vector2_angle_to:
  79. - :ref:`float<class_float>` **angle_to** **(** :ref:`Vector2<class_vector2>` to **)**
  80. Returns the angle in radians between the two vectors.
  81. .. _class_Vector2_angle_to_point:
  82. - :ref:`float<class_float>` **angle_to_point** **(** :ref:`Vector2<class_vector2>` to **)**
  83. Returns the angle in radians between the line connecting the two points and the x coordinate.
  84. .. _class_Vector2_clamped:
  85. - :ref:`Vector2<class_vector2>` **clamped** **(** :ref:`float<class_float>` length **)**
  86. Returns the vector with a maximum length.
  87. .. _class_Vector2_cubic_interpolate:
  88. - :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 **)**
  89. Cubicly interpolates between this Vector and "b", using "pre_a" and "post_b" as handles, and returning the result at position "t".
  90. .. _class_Vector2_distance_squared_to:
  91. - :ref:`float<class_float>` **distance_squared_to** **(** :ref:`Vector2<class_vector2>` to **)**
  92. Returns the squared distance to vector "b". Prefer this function over "distance_to" if you need to sort vectors or need the squared distance for some formula.
  93. .. _class_Vector2_distance_to:
  94. - :ref:`float<class_float>` **distance_to** **(** :ref:`Vector2<class_vector2>` to **)**
  95. Returns the distance to vector "b".
  96. .. _class_Vector2_dot:
  97. - :ref:`float<class_float>` **dot** **(** :ref:`Vector2<class_vector2>` with **)**
  98. Returns the dot product with vector "b".
  99. .. _class_Vector2_floor:
  100. - :ref:`Vector2<class_vector2>` **floor** **(** **)**
  101. Remove the fractional part of x and y.
  102. .. _class_Vector2_floorf:
  103. - :ref:`Vector2<class_vector2>` **floorf** **(** **)**
  104. Remove the fractional part of x and y.
  105. .. _class_Vector2_get_aspect:
  106. - :ref:`float<class_float>` **get_aspect** **(** **)**
  107. Returns the ratio of X to Y.
  108. .. _class_Vector2_length:
  109. - :ref:`float<class_float>` **length** **(** **)**
  110. Returns the length of the vector.
  111. .. _class_Vector2_length_squared:
  112. - :ref:`float<class_float>` **length_squared** **(** **)**
  113. Returns the squared length of the vector. Prefer this function over "length" if you need to sort vectors or need the squared length for some formula.
  114. .. _class_Vector2_linear_interpolate:
  115. - :ref:`Vector2<class_vector2>` **linear_interpolate** **(** :ref:`Vector2<class_vector2>` b, :ref:`float<class_float>` t **)**
  116. Returns the result of the linear interpolation between this vector and "b", by amount "t".
  117. .. _class_Vector2_normalized:
  118. - :ref:`Vector2<class_vector2>` **normalized** **(** **)**
  119. Returns a normalized vector to unit length.
  120. .. _class_Vector2_reflect:
  121. - :ref:`Vector2<class_vector2>` **reflect** **(** :ref:`Vector2<class_vector2>` vec **)**
  122. Like "slide", but reflects the Vector instead of continuing along the wall.
  123. .. _class_Vector2_rotated:
  124. - :ref:`Vector2<class_vector2>` **rotated** **(** :ref:`float<class_float>` phi **)**
  125. Rotates the vector by "phi" radians.
  126. .. _class_Vector2_slide:
  127. - :ref:`Vector2<class_vector2>` **slide** **(** :ref:`Vector2<class_vector2>` vec **)**
  128. Slides the vector by the other vector.
  129. .. _class_Vector2_snapped:
  130. - :ref:`Vector2<class_vector2>` **snapped** **(** :ref:`Vector2<class_vector2>` by **)**
  131. Snaps the vector to a grid with the given size.
  132. .. _class_Vector2_tangent:
  133. - :ref:`Vector2<class_vector2>` **tangent** **(** **)**
  134. Returns a perpendicular vector.