class_vector2.rst 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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:`float<class_float>` | :ref:`angle<class_Vector2_angle>` **(** **)** |
  14. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  15. | :ref:`float<class_float>` | :ref:`angle_to<class_Vector2_angle_to>` **(** :ref:`Vector2<class_vector2>` to **)** |
  16. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  17. | :ref:`float<class_float>` | :ref:`angle_to_point<class_Vector2_angle_to_point>` **(** :ref:`Vector2<class_vector2>` to **)** |
  18. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  19. | :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 **)** |
  20. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  21. | :ref:`float<class_float>` | :ref:`distance_squared_to<class_Vector2_distance_squared_to>` **(** :ref:`Vector2<class_vector2>` to **)** |
  22. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  23. | :ref:`float<class_float>` | :ref:`distance_to<class_Vector2_distance_to>` **(** :ref:`Vector2<class_vector2>` to **)** |
  24. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  25. | :ref:`float<class_float>` | :ref:`dot<class_Vector2_dot>` **(** :ref:`Vector2<class_vector2>` with **)** |
  26. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  27. | :ref:`Vector2<class_vector2>` | :ref:`floor<class_Vector2_floor>` **(** **)** |
  28. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  29. | :ref:`Vector2<class_vector2>` | :ref:`floorf<class_Vector2_floorf>` **(** **)** |
  30. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  31. | :ref:`float<class_float>` | :ref:`get_aspect<class_Vector2_get_aspect>` **(** **)** |
  32. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  33. | :ref:`float<class_float>` | :ref:`length<class_Vector2_length>` **(** **)** |
  34. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  35. | :ref:`float<class_float>` | :ref:`length_squared<class_Vector2_length_squared>` **(** **)** |
  36. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  37. | :ref:`Vector2<class_vector2>` | :ref:`linear_interpolate<class_Vector2_linear_interpolate>` **(** :ref:`Vector2<class_vector2>` b, :ref:`float<class_float>` t **)** |
  38. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  39. | :ref:`Vector2<class_vector2>` | :ref:`normalized<class_Vector2_normalized>` **(** **)** |
  40. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  41. | :ref:`Vector2<class_vector2>` | :ref:`reflect<class_Vector2_reflect>` **(** :ref:`Vector2<class_vector2>` vec **)** |
  42. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  43. | :ref:`Vector2<class_vector2>` | :ref:`rotated<class_Vector2_rotated>` **(** :ref:`float<class_float>` phi **)** |
  44. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  45. | :ref:`Vector2<class_vector2>` | :ref:`slide<class_Vector2_slide>` **(** :ref:`Vector2<class_vector2>` vec **)** |
  46. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  47. | :ref:`Vector2<class_vector2>` | :ref:`snapped<class_Vector2_snapped>` **(** :ref:`Vector2<class_vector2>` by **)** |
  48. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  49. | :ref:`Vector2<class_vector2>` | :ref:`tangent<class_Vector2_tangent>` **(** **)** |
  50. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  51. | :ref:`Vector2<class_vector2>` | :ref:`Vector2<class_Vector2_Vector2>` **(** :ref:`float<class_float>` x, :ref:`float<class_float>` y **)** |
  52. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  53. Member Variables
  54. ----------------
  55. - :ref:`float<class_float>` **x**
  56. - :ref:`float<class_float>` **y**
  57. - :ref:`float<class_float>` **width**
  58. - :ref:`float<class_float>` **height**
  59. Description
  60. -----------
  61. 2-element structure that can be used to represent positions in 2d-space, or any other pair of numeric values.
  62. Member Function Description
  63. ---------------------------
  64. .. _class_Vector2_angle:
  65. - :ref:`float<class_float>` **angle** **(** **)**
  66. Returns the result of atan2 when called with the Vector's x and y as parameters (Math::atan2(x,y)).
  67. 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)).
  68. .. _class_Vector2_angle_to:
  69. - :ref:`float<class_float>` **angle_to** **(** :ref:`Vector2<class_vector2>` to **)**
  70. Returns the angle in radians between the two vectors.
  71. .. _class_Vector2_angle_to_point:
  72. - :ref:`float<class_float>` **angle_to_point** **(** :ref:`Vector2<class_vector2>` to **)**
  73. Returns the angle in radians between the line connecting the two points and the x coordinate.
  74. .. _class_Vector2_cubic_interpolate:
  75. - :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 **)**
  76. Cubicly interpolates between this Vector and "b", using "pre_a" and "post_b" as handles, and returning the result at position "t".
  77. .. _class_Vector2_distance_squared_to:
  78. - :ref:`float<class_float>` **distance_squared_to** **(** :ref:`Vector2<class_vector2>` to **)**
  79. 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.
  80. .. _class_Vector2_distance_to:
  81. - :ref:`float<class_float>` **distance_to** **(** :ref:`Vector2<class_vector2>` to **)**
  82. Returns the distance to vector "b".
  83. .. _class_Vector2_dot:
  84. - :ref:`float<class_float>` **dot** **(** :ref:`Vector2<class_vector2>` with **)**
  85. Returns the dot product with vector "b".
  86. .. _class_Vector2_floor:
  87. - :ref:`Vector2<class_vector2>` **floor** **(** **)**
  88. Remove the fractional part of x and y.
  89. .. _class_Vector2_floorf:
  90. - :ref:`Vector2<class_vector2>` **floorf** **(** **)**
  91. Remove the fractional part of x and y.
  92. .. _class_Vector2_get_aspect:
  93. - :ref:`float<class_float>` **get_aspect** **(** **)**
  94. Returns the ratio of X to Y.
  95. .. _class_Vector2_length:
  96. - :ref:`float<class_float>` **length** **(** **)**
  97. Returns the length of the vector.
  98. .. _class_Vector2_length_squared:
  99. - :ref:`float<class_float>` **length_squared** **(** **)**
  100. 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.
  101. .. _class_Vector2_linear_interpolate:
  102. - :ref:`Vector2<class_vector2>` **linear_interpolate** **(** :ref:`Vector2<class_vector2>` b, :ref:`float<class_float>` t **)**
  103. Returns the result of the linear interpolation between this vector and "b", by amount "t".
  104. .. _class_Vector2_normalized:
  105. - :ref:`Vector2<class_vector2>` **normalized** **(** **)**
  106. Returns a normalized vector to unit length.
  107. .. _class_Vector2_reflect:
  108. - :ref:`Vector2<class_vector2>` **reflect** **(** :ref:`Vector2<class_vector2>` vec **)**
  109. Like "slide", but reflects the Vector instead of continuing along the wall.
  110. .. _class_Vector2_rotated:
  111. - :ref:`Vector2<class_vector2>` **rotated** **(** :ref:`float<class_float>` phi **)**
  112. Rotates the vector by "phi" radians.
  113. .. _class_Vector2_slide:
  114. - :ref:`Vector2<class_vector2>` **slide** **(** :ref:`Vector2<class_vector2>` vec **)**
  115. Slides the vector by the other vector.
  116. .. _class_Vector2_snapped:
  117. - :ref:`Vector2<class_vector2>` **snapped** **(** :ref:`Vector2<class_vector2>` by **)**
  118. Snaps the vector to a grid with the given size.
  119. .. _class_Vector2_tangent:
  120. - :ref:`Vector2<class_vector2>` **tangent** **(** **)**
  121. Returns a perpendicular vector.
  122. .. _class_Vector2_Vector2:
  123. - :ref:`Vector2<class_vector2>` **Vector2** **(** :ref:`float<class_float>` x, :ref:`float<class_float>` y **)**
  124. Constructs a new Vector2 from the given x and y.