class_vector2.rst 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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:`clamped<class_Vector2_clamped>` **(** :ref:`float<class_float>` length **)** |
  29. +--------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  30. | :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 **)** |
  31. +--------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  32. | :ref:`float<class_float>` | :ref:`distance_squared_to<class_Vector2_distance_squared_to>` **(** :ref:`Vector2<class_vector2>` to **)** |
  33. +--------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  34. | :ref:`float<class_float>` | :ref:`distance_to<class_Vector2_distance_to>` **(** :ref:`Vector2<class_vector2>` to **)** |
  35. +--------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  36. | :ref:`float<class_float>` | :ref:`dot<class_Vector2_dot>` **(** :ref:`Vector2<class_vector2>` with **)** |
  37. +--------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  38. | :ref:`Vector2<class_vector2>` | :ref:`floor<class_Vector2_floor>` **(** **)** |
  39. +--------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  40. | :ref:`bool<class_bool>` | :ref:`is_normalized<class_Vector2_is_normalized>` **(** **)** |
  41. +--------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  42. | :ref:`float<class_float>` | :ref:`length<class_Vector2_length>` **(** **)** |
  43. +--------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  44. | :ref:`float<class_float>` | :ref:`length_squared<class_Vector2_length_squared>` **(** **)** |
  45. +--------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  46. | :ref:`Vector2<class_vector2>` | :ref:`linear_interpolate<class_Vector2_linear_interpolate>` **(** :ref:`Vector2<class_vector2>` b, :ref:`float<class_float>` t **)** |
  47. +--------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  48. | :ref:`Vector2<class_vector2>` | :ref:`normalized<class_Vector2_normalized>` **(** **)** |
  49. +--------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  50. | :ref:`Vector2<class_vector2>` | :ref:`reflect<class_Vector2_reflect>` **(** :ref:`Vector2<class_vector2>` n **)** |
  51. +--------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  52. | :ref:`Vector2<class_vector2>` | :ref:`rotated<class_Vector2_rotated>` **(** :ref:`float<class_float>` phi **)** |
  53. +--------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  54. | :ref:`Vector2<class_vector2>` | :ref:`slide<class_Vector2_slide>` **(** :ref:`Vector2<class_vector2>` n **)** |
  55. +--------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  56. | :ref:`Vector2<class_vector2>` | :ref:`snapped<class_Vector2_snapped>` **(** :ref:`Vector2<class_vector2>` by **)** |
  57. +--------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  58. | :ref:`Vector2<class_vector2>` | :ref:`tangent<class_Vector2_tangent>` **(** **)** |
  59. +--------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  60. Member Variables
  61. ----------------
  62. .. _class_Vector2_x:
  63. - :ref:`float<class_float>` **x** - X component of the vector.
  64. .. _class_Vector2_y:
  65. - :ref:`float<class_float>` **y** - Y component of the vector.
  66. Description
  67. -----------
  68. 2-element structure that can be used to represent positions in 2d-space, or any other pair of numeric values.
  69. Member Function Description
  70. ---------------------------
  71. .. _class_Vector2_Vector2:
  72. - :ref:`Vector2<class_vector2>` **Vector2** **(** :ref:`float<class_float>` x, :ref:`float<class_float>` y **)**
  73. Constructs a new Vector2 from the given x and y.
  74. .. _class_Vector2_abs:
  75. - :ref:`Vector2<class_vector2>` **abs** **(** **)**
  76. Returns a new vector with all components in absolute values (i.e. positive).
  77. .. _class_Vector2_angle:
  78. - :ref:`float<class_float>` **angle** **(** **)**
  79. Returns the result of atan2 when called with the Vector's x and y as parameters (Math::atan2(x,y)).
  80. 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)).
  81. .. _class_Vector2_angle_to:
  82. - :ref:`float<class_float>` **angle_to** **(** :ref:`Vector2<class_vector2>` to **)**
  83. Returns the angle in radians between the two vectors.
  84. .. _class_Vector2_angle_to_point:
  85. - :ref:`float<class_float>` **angle_to_point** **(** :ref:`Vector2<class_vector2>` to **)**
  86. Returns the angle in radians between the line connecting the two points and the x coordinate.
  87. .. _class_Vector2_aspect:
  88. - :ref:`float<class_float>` **aspect** **(** **)**
  89. Returns the ratio of X to Y.
  90. .. _class_Vector2_bounce:
  91. - :ref:`Vector2<class_vector2>` **bounce** **(** :ref:`Vector2<class_vector2>` n **)**
  92. Bounce returns the vector "bounced off" from the given plane, specified by its normal vector.
  93. .. _class_Vector2_clamped:
  94. - :ref:`Vector2<class_vector2>` **clamped** **(** :ref:`float<class_float>` length **)**
  95. Returns the vector with a maximum length.
  96. .. _class_Vector2_cubic_interpolate:
  97. - :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 **)**
  98. Cubicly interpolates between this Vector and "b", using "pre_a" and "post_b" as handles, and returning the result at position "t". "t" should be a float of 0.0-1.0, a percentage of how far along the interpolation is.
  99. .. _class_Vector2_distance_squared_to:
  100. - :ref:`float<class_float>` **distance_squared_to** **(** :ref:`Vector2<class_vector2>` to **)**
  101. 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.
  102. .. _class_Vector2_distance_to:
  103. - :ref:`float<class_float>` **distance_to** **(** :ref:`Vector2<class_vector2>` to **)**
  104. Returns the distance to vector "b".
  105. .. _class_Vector2_dot:
  106. - :ref:`float<class_float>` **dot** **(** :ref:`Vector2<class_vector2>` with **)**
  107. Returns the dot product with vector "b".
  108. .. _class_Vector2_floor:
  109. - :ref:`Vector2<class_vector2>` **floor** **(** **)**
  110. Remove the fractional part of x and y.
  111. .. _class_Vector2_is_normalized:
  112. - :ref:`bool<class_bool>` **is_normalized** **(** **)**
  113. Returns whether the vector is normalized or not.
  114. .. _class_Vector2_length:
  115. - :ref:`float<class_float>` **length** **(** **)**
  116. Returns the length of the vector.
  117. .. _class_Vector2_length_squared:
  118. - :ref:`float<class_float>` **length_squared** **(** **)**
  119. 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.
  120. .. _class_Vector2_linear_interpolate:
  121. - :ref:`Vector2<class_vector2>` **linear_interpolate** **(** :ref:`Vector2<class_vector2>` b, :ref:`float<class_float>` t **)**
  122. Returns the result of the linear interpolation 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.
  123. .. _class_Vector2_normalized:
  124. - :ref:`Vector2<class_vector2>` **normalized** **(** **)**
  125. Returns a normalized vector to unit length.
  126. .. _class_Vector2_reflect:
  127. - :ref:`Vector2<class_vector2>` **reflect** **(** :ref:`Vector2<class_vector2>` n **)**
  128. Reflects the vector along the given plane, specified by its normal vector.
  129. .. _class_Vector2_rotated:
  130. - :ref:`Vector2<class_vector2>` **rotated** **(** :ref:`float<class_float>` phi **)**
  131. Rotates the vector by "phi" radians.
  132. .. _class_Vector2_slide:
  133. - :ref:`Vector2<class_vector2>` **slide** **(** :ref:`Vector2<class_vector2>` n **)**
  134. Slide returns the component of the vector along the given plane, specified by its normal vector.
  135. .. _class_Vector2_snapped:
  136. - :ref:`Vector2<class_vector2>` **snapped** **(** :ref:`Vector2<class_vector2>` by **)**
  137. Snaps the vector to a grid with the given size.
  138. .. _class_Vector2_tangent:
  139. - :ref:`Vector2<class_vector2>` **tangent** **(** **)**
  140. Returns a perpendicular vector.