class_aabb.rst 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778
  1. :github_url: hide
  2. .. DO NOT EDIT THIS FILE!!!
  3. .. Generated automatically from Godot engine sources.
  4. .. Generator: https://github.com/godotengine/godot/tree/master/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/master/doc/classes/AABB.xml.
  6. .. _class_AABB:
  7. AABB
  8. ====
  9. A 3D axis-aligned bounding box.
  10. .. rst-class:: classref-introduction-group
  11. Description
  12. -----------
  13. The **AABB** built-in :ref:`Variant<class_Variant>` type represents an axis-aligned bounding box in a 3D space. It is defined by its :ref:`position<class_AABB_property_position>` and :ref:`size<class_AABB_property_size>`, which are :ref:`Vector3<class_Vector3>`. It is frequently used for fast overlap tests (see :ref:`intersects<class_AABB_method_intersects>`). Although **AABB** itself is axis-aligned, it can be combined with :ref:`Transform3D<class_Transform3D>` to represent a rotated or skewed bounding box.
  14. It uses floating-point coordinates. The 2D counterpart to **AABB** is :ref:`Rect2<class_Rect2>`. There is no version of **AABB** that uses integer coordinates.
  15. \ **Note:** Negative values for :ref:`size<class_AABB_property_size>` are not supported. With negative size, most **AABB** methods do not work correctly. Use :ref:`abs<class_AABB_method_abs>` to get an equivalent **AABB** with a non-negative size.
  16. \ **Note:** In a boolean context, a **AABB** evaluates to ``false`` if both :ref:`position<class_AABB_property_position>` and :ref:`size<class_AABB_property_size>` are zero (equal to :ref:`Vector3.ZERO<class_Vector3_constant_ZERO>`). Otherwise, it always evaluates to ``true``.
  17. .. note::
  18. There are notable differences when using this API with C#. See :ref:`doc_c_sharp_differences` for more information.
  19. .. rst-class:: classref-introduction-group
  20. Tutorials
  21. ---------
  22. - :doc:`Math documentation index <../tutorials/math/index>`
  23. - :doc:`Vector math <../tutorials/math/vector_math>`
  24. - :doc:`Advanced vector math <../tutorials/math/vectors_advanced>`
  25. .. rst-class:: classref-reftable-group
  26. Properties
  27. ----------
  28. .. table::
  29. :widths: auto
  30. +-------------------------------+-----------------------------------------------+----------------------+
  31. | :ref:`Vector3<class_Vector3>` | :ref:`end<class_AABB_property_end>` | ``Vector3(0, 0, 0)`` |
  32. +-------------------------------+-----------------------------------------------+----------------------+
  33. | :ref:`Vector3<class_Vector3>` | :ref:`position<class_AABB_property_position>` | ``Vector3(0, 0, 0)`` |
  34. +-------------------------------+-----------------------------------------------+----------------------+
  35. | :ref:`Vector3<class_Vector3>` | :ref:`size<class_AABB_property_size>` | ``Vector3(0, 0, 0)`` |
  36. +-------------------------------+-----------------------------------------------+----------------------+
  37. .. rst-class:: classref-reftable-group
  38. Constructors
  39. ------------
  40. .. table::
  41. :widths: auto
  42. +-------------------------+--------------------------------------------------------------------------------------------------------------------------------+
  43. | :ref:`AABB<class_AABB>` | :ref:`AABB<class_AABB_constructor_AABB>`\ (\ ) |
  44. +-------------------------+--------------------------------------------------------------------------------------------------------------------------------+
  45. | :ref:`AABB<class_AABB>` | :ref:`AABB<class_AABB_constructor_AABB>`\ (\ from\: :ref:`AABB<class_AABB>`\ ) |
  46. +-------------------------+--------------------------------------------------------------------------------------------------------------------------------+
  47. | :ref:`AABB<class_AABB>` | :ref:`AABB<class_AABB_constructor_AABB>`\ (\ position\: :ref:`Vector3<class_Vector3>`, size\: :ref:`Vector3<class_Vector3>`\ ) |
  48. +-------------------------+--------------------------------------------------------------------------------------------------------------------------------+
  49. .. rst-class:: classref-reftable-group
  50. Methods
  51. -------
  52. .. table::
  53. :widths: auto
  54. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
  55. | :ref:`AABB<class_AABB>` | :ref:`abs<class_AABB_method_abs>`\ (\ ) |const| |
  56. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
  57. | :ref:`bool<class_bool>` | :ref:`encloses<class_AABB_method_encloses>`\ (\ with\: :ref:`AABB<class_AABB>`\ ) |const| |
  58. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
  59. | :ref:`AABB<class_AABB>` | :ref:`expand<class_AABB_method_expand>`\ (\ to_point\: :ref:`Vector3<class_Vector3>`\ ) |const| |
  60. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
  61. | :ref:`Vector3<class_Vector3>` | :ref:`get_center<class_AABB_method_get_center>`\ (\ ) |const| |
  62. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
  63. | :ref:`Vector3<class_Vector3>` | :ref:`get_endpoint<class_AABB_method_get_endpoint>`\ (\ idx\: :ref:`int<class_int>`\ ) |const| |
  64. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
  65. | :ref:`Vector3<class_Vector3>` | :ref:`get_longest_axis<class_AABB_method_get_longest_axis>`\ (\ ) |const| |
  66. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
  67. | :ref:`int<class_int>` | :ref:`get_longest_axis_index<class_AABB_method_get_longest_axis_index>`\ (\ ) |const| |
  68. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
  69. | :ref:`float<class_float>` | :ref:`get_longest_axis_size<class_AABB_method_get_longest_axis_size>`\ (\ ) |const| |
  70. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
  71. | :ref:`Vector3<class_Vector3>` | :ref:`get_shortest_axis<class_AABB_method_get_shortest_axis>`\ (\ ) |const| |
  72. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
  73. | :ref:`int<class_int>` | :ref:`get_shortest_axis_index<class_AABB_method_get_shortest_axis_index>`\ (\ ) |const| |
  74. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
  75. | :ref:`float<class_float>` | :ref:`get_shortest_axis_size<class_AABB_method_get_shortest_axis_size>`\ (\ ) |const| |
  76. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
  77. | :ref:`Vector3<class_Vector3>` | :ref:`get_support<class_AABB_method_get_support>`\ (\ direction\: :ref:`Vector3<class_Vector3>`\ ) |const| |
  78. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
  79. | :ref:`float<class_float>` | :ref:`get_volume<class_AABB_method_get_volume>`\ (\ ) |const| |
  80. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
  81. | :ref:`AABB<class_AABB>` | :ref:`grow<class_AABB_method_grow>`\ (\ by\: :ref:`float<class_float>`\ ) |const| |
  82. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
  83. | :ref:`bool<class_bool>` | :ref:`has_point<class_AABB_method_has_point>`\ (\ point\: :ref:`Vector3<class_Vector3>`\ ) |const| |
  84. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
  85. | :ref:`bool<class_bool>` | :ref:`has_surface<class_AABB_method_has_surface>`\ (\ ) |const| |
  86. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
  87. | :ref:`bool<class_bool>` | :ref:`has_volume<class_AABB_method_has_volume>`\ (\ ) |const| |
  88. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
  89. | :ref:`AABB<class_AABB>` | :ref:`intersection<class_AABB_method_intersection>`\ (\ with\: :ref:`AABB<class_AABB>`\ ) |const| |
  90. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
  91. | :ref:`bool<class_bool>` | :ref:`intersects<class_AABB_method_intersects>`\ (\ with\: :ref:`AABB<class_AABB>`\ ) |const| |
  92. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
  93. | :ref:`bool<class_bool>` | :ref:`intersects_plane<class_AABB_method_intersects_plane>`\ (\ plane\: :ref:`Plane<class_Plane>`\ ) |const| |
  94. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
  95. | :ref:`Variant<class_Variant>` | :ref:`intersects_ray<class_AABB_method_intersects_ray>`\ (\ from\: :ref:`Vector3<class_Vector3>`, dir\: :ref:`Vector3<class_Vector3>`\ ) |const| |
  96. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
  97. | :ref:`Variant<class_Variant>` | :ref:`intersects_segment<class_AABB_method_intersects_segment>`\ (\ from\: :ref:`Vector3<class_Vector3>`, to\: :ref:`Vector3<class_Vector3>`\ ) |const| |
  98. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
  99. | :ref:`bool<class_bool>` | :ref:`is_equal_approx<class_AABB_method_is_equal_approx>`\ (\ aabb\: :ref:`AABB<class_AABB>`\ ) |const| |
  100. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
  101. | :ref:`bool<class_bool>` | :ref:`is_finite<class_AABB_method_is_finite>`\ (\ ) |const| |
  102. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
  103. | :ref:`AABB<class_AABB>` | :ref:`merge<class_AABB_method_merge>`\ (\ with\: :ref:`AABB<class_AABB>`\ ) |const| |
  104. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
  105. .. rst-class:: classref-reftable-group
  106. Operators
  107. ---------
  108. .. table::
  109. :widths: auto
  110. +-------------------------+-------------------------------------------------------------------------------------------------------------+
  111. | :ref:`bool<class_bool>` | :ref:`operator !=<class_AABB_operator_neq_AABB>`\ (\ right\: :ref:`AABB<class_AABB>`\ ) |
  112. +-------------------------+-------------------------------------------------------------------------------------------------------------+
  113. | :ref:`AABB<class_AABB>` | :ref:`operator *<class_AABB_operator_mul_Transform3D>`\ (\ right\: :ref:`Transform3D<class_Transform3D>`\ ) |
  114. +-------------------------+-------------------------------------------------------------------------------------------------------------+
  115. | :ref:`bool<class_bool>` | :ref:`operator ==<class_AABB_operator_eq_AABB>`\ (\ right\: :ref:`AABB<class_AABB>`\ ) |
  116. +-------------------------+-------------------------------------------------------------------------------------------------------------+
  117. .. rst-class:: classref-section-separator
  118. ----
  119. .. rst-class:: classref-descriptions-group
  120. Property Descriptions
  121. ---------------------
  122. .. _class_AABB_property_end:
  123. .. rst-class:: classref-property
  124. :ref:`Vector3<class_Vector3>` **end** = ``Vector3(0, 0, 0)`` :ref:`🔗<class_AABB_property_end>`
  125. The ending point. This is usually the corner on the top-right and forward of the bounding box, and is equivalent to ``position + size``. Setting this point affects the :ref:`size<class_AABB_property_size>`.
  126. .. rst-class:: classref-item-separator
  127. ----
  128. .. _class_AABB_property_position:
  129. .. rst-class:: classref-property
  130. :ref:`Vector3<class_Vector3>` **position** = ``Vector3(0, 0, 0)`` :ref:`🔗<class_AABB_property_position>`
  131. The origin point. This is usually the corner on the bottom-left and back of the bounding box.
  132. .. rst-class:: classref-item-separator
  133. ----
  134. .. _class_AABB_property_size:
  135. .. rst-class:: classref-property
  136. :ref:`Vector3<class_Vector3>` **size** = ``Vector3(0, 0, 0)`` :ref:`🔗<class_AABB_property_size>`
  137. The bounding box's width, height, and depth starting from :ref:`position<class_AABB_property_position>`. Setting this value also affects the :ref:`end<class_AABB_property_end>` point.
  138. \ **Note:** It's recommended setting the width, height, and depth to non-negative values. This is because most methods in Godot assume that the :ref:`position<class_AABB_property_position>` is the bottom-left-back corner, and the :ref:`end<class_AABB_property_end>` is the top-right-forward corner. To get an equivalent bounding box with non-negative size, use :ref:`abs<class_AABB_method_abs>`.
  139. .. rst-class:: classref-section-separator
  140. ----
  141. .. rst-class:: classref-descriptions-group
  142. Constructor Descriptions
  143. ------------------------
  144. .. _class_AABB_constructor_AABB:
  145. .. rst-class:: classref-constructor
  146. :ref:`AABB<class_AABB>` **AABB**\ (\ ) :ref:`🔗<class_AABB_constructor_AABB>`
  147. Constructs an **AABB** with its :ref:`position<class_AABB_property_position>` and :ref:`size<class_AABB_property_size>` set to :ref:`Vector3.ZERO<class_Vector3_constant_ZERO>`.
  148. .. rst-class:: classref-item-separator
  149. ----
  150. .. rst-class:: classref-constructor
  151. :ref:`AABB<class_AABB>` **AABB**\ (\ from\: :ref:`AABB<class_AABB>`\ )
  152. Constructs an **AABB** as a copy of the given **AABB**.
  153. .. rst-class:: classref-item-separator
  154. ----
  155. .. rst-class:: classref-constructor
  156. :ref:`AABB<class_AABB>` **AABB**\ (\ position\: :ref:`Vector3<class_Vector3>`, size\: :ref:`Vector3<class_Vector3>`\ )
  157. Constructs an **AABB** by ``position`` and ``size``.
  158. .. rst-class:: classref-section-separator
  159. ----
  160. .. rst-class:: classref-descriptions-group
  161. Method Descriptions
  162. -------------------
  163. .. _class_AABB_method_abs:
  164. .. rst-class:: classref-method
  165. :ref:`AABB<class_AABB>` **abs**\ (\ ) |const| :ref:`🔗<class_AABB_method_abs>`
  166. Returns an **AABB** equivalent to this bounding box, with its width, height, and depth modified to be non-negative values.
  167. .. tabs::
  168. .. code-tab:: gdscript
  169. var box = AABB(Vector3(5, 0, 5), Vector3(-20, -10, -5))
  170. var absolute = box.abs()
  171. print(absolute.position) # Prints (-15, -10, 0)
  172. print(absolute.size) # Prints (20, 10, 5)
  173. .. code-tab:: csharp
  174. var box = new Aabb(new Vector3(5, 0, 5), new Vector3(-20, -10, -5));
  175. var absolute = box.Abs();
  176. GD.Print(absolute.Position); // Prints (-15, -10, 0)
  177. GD.Print(absolute.Size); // Prints (20, 10, 5)
  178. \ **Note:** It's recommended to use this method when :ref:`size<class_AABB_property_size>` is negative, as most other methods in Godot assume that the :ref:`size<class_AABB_property_size>`'s components are greater than ``0``.
  179. .. rst-class:: classref-item-separator
  180. ----
  181. .. _class_AABB_method_encloses:
  182. .. rst-class:: classref-method
  183. :ref:`bool<class_bool>` **encloses**\ (\ with\: :ref:`AABB<class_AABB>`\ ) |const| :ref:`🔗<class_AABB_method_encloses>`
  184. Returns ``true`` if this bounding box *completely* encloses the ``with`` box. The edges of both boxes are included.
  185. .. tabs::
  186. .. code-tab:: gdscript
  187. var a = AABB(Vector3(0, 0, 0), Vector3(4, 4, 4))
  188. var b = AABB(Vector3(1, 1, 1), Vector3(3, 3, 3))
  189. var c = AABB(Vector3(2, 2, 2), Vector3(8, 8, 8))
  190. print(a.encloses(a)) # Prints true
  191. print(a.encloses(b)) # Prints true
  192. print(a.encloses(c)) # Prints false
  193. .. code-tab:: csharp
  194. var a = new Aabb(new Vector3(0, 0, 0), new Vector3(4, 4, 4));
  195. var b = new Aabb(new Vector3(1, 1, 1), new Vector3(3, 3, 3));
  196. var c = new Aabb(new Vector3(2, 2, 2), new Vector3(8, 8, 8));
  197. GD.Print(a.Encloses(a)); // Prints True
  198. GD.Print(a.Encloses(b)); // Prints True
  199. GD.Print(a.Encloses(c)); // Prints False
  200. .. rst-class:: classref-item-separator
  201. ----
  202. .. _class_AABB_method_expand:
  203. .. rst-class:: classref-method
  204. :ref:`AABB<class_AABB>` **expand**\ (\ to_point\: :ref:`Vector3<class_Vector3>`\ ) |const| :ref:`🔗<class_AABB_method_expand>`
  205. Returns a copy of this bounding box expanded to align the edges with the given ``to_point``, if necessary.
  206. .. tabs::
  207. .. code-tab:: gdscript
  208. var box = AABB(Vector3(0, 0, 0), Vector3(5, 2, 5))
  209. box = box.expand(Vector3(10, 0, 0))
  210. print(box.position) # Prints (0, 0, 0)
  211. print(box.size) # Prints (10, 2, 5)
  212. box = box.expand(Vector3(-5, 0, 5))
  213. print(box.position) # Prints (-5, 0, 0)
  214. print(box.size) # Prints (15, 2, 5)
  215. .. code-tab:: csharp
  216. var box = new Aabb(new Vector3(0, 0, 0), new Vector3(5, 2, 5));
  217. box = box.Expand(new Vector3(10, 0, 0));
  218. GD.Print(box.Position); // Prints (0, 0, 0)
  219. GD.Print(box.Size); // Prints (10, 2, 5)
  220. box = box.Expand(new Vector3(-5, 0, 5));
  221. GD.Print(box.Position); // Prints (-5, 0, 0)
  222. GD.Print(box.Size); // Prints (15, 2, 5)
  223. .. rst-class:: classref-item-separator
  224. ----
  225. .. _class_AABB_method_get_center:
  226. .. rst-class:: classref-method
  227. :ref:`Vector3<class_Vector3>` **get_center**\ (\ ) |const| :ref:`🔗<class_AABB_method_get_center>`
  228. Returns the center point of the bounding box. This is the same as ``position + (size / 2.0)``.
  229. .. rst-class:: classref-item-separator
  230. ----
  231. .. _class_AABB_method_get_endpoint:
  232. .. rst-class:: classref-method
  233. :ref:`Vector3<class_Vector3>` **get_endpoint**\ (\ idx\: :ref:`int<class_int>`\ ) |const| :ref:`🔗<class_AABB_method_get_endpoint>`
  234. Returns the position of one of the 8 vertices that compose this bounding box. With a ``idx`` of ``0`` this is the same as :ref:`position<class_AABB_property_position>`, and a ``idx`` of ``7`` is the same as :ref:`end<class_AABB_property_end>`.
  235. .. rst-class:: classref-item-separator
  236. ----
  237. .. _class_AABB_method_get_longest_axis:
  238. .. rst-class:: classref-method
  239. :ref:`Vector3<class_Vector3>` **get_longest_axis**\ (\ ) |const| :ref:`🔗<class_AABB_method_get_longest_axis>`
  240. Returns the longest normalized axis of this bounding box's :ref:`size<class_AABB_property_size>`, as a :ref:`Vector3<class_Vector3>` (:ref:`Vector3.RIGHT<class_Vector3_constant_RIGHT>`, :ref:`Vector3.UP<class_Vector3_constant_UP>`, or :ref:`Vector3.BACK<class_Vector3_constant_BACK>`).
  241. .. tabs::
  242. .. code-tab:: gdscript
  243. var box = AABB(Vector3(0, 0, 0), Vector3(2, 4, 8))
  244. print(box.get_longest_axis()) # Prints (0, 0, 1)
  245. print(box.get_longest_axis_index()) # Prints 2
  246. print(box.get_longest_axis_size()) # Prints 8
  247. .. code-tab:: csharp
  248. var box = new Aabb(new Vector3(0, 0, 0), new Vector3(2, 4, 8));
  249. GD.Print(box.GetLongestAxis()); // Prints (0, 0, 1)
  250. GD.Print(box.GetLongestAxisIndex()); // Prints 2
  251. GD.Print(box.GetLongestAxisSize()); // Prints 8
  252. See also :ref:`get_longest_axis_index<class_AABB_method_get_longest_axis_index>` and :ref:`get_longest_axis_size<class_AABB_method_get_longest_axis_size>`.
  253. .. rst-class:: classref-item-separator
  254. ----
  255. .. _class_AABB_method_get_longest_axis_index:
  256. .. rst-class:: classref-method
  257. :ref:`int<class_int>` **get_longest_axis_index**\ (\ ) |const| :ref:`🔗<class_AABB_method_get_longest_axis_index>`
  258. Returns the index to the longest axis of this bounding box's :ref:`size<class_AABB_property_size>` (see :ref:`Vector3.AXIS_X<class_Vector3_constant_AXIS_X>`, :ref:`Vector3.AXIS_Y<class_Vector3_constant_AXIS_Y>`, and :ref:`Vector3.AXIS_Z<class_Vector3_constant_AXIS_Z>`).
  259. For an example, see :ref:`get_longest_axis<class_AABB_method_get_longest_axis>`.
  260. .. rst-class:: classref-item-separator
  261. ----
  262. .. _class_AABB_method_get_longest_axis_size:
  263. .. rst-class:: classref-method
  264. :ref:`float<class_float>` **get_longest_axis_size**\ (\ ) |const| :ref:`🔗<class_AABB_method_get_longest_axis_size>`
  265. Returns the longest dimension of this bounding box's :ref:`size<class_AABB_property_size>`.
  266. For an example, see :ref:`get_longest_axis<class_AABB_method_get_longest_axis>`.
  267. .. rst-class:: classref-item-separator
  268. ----
  269. .. _class_AABB_method_get_shortest_axis:
  270. .. rst-class:: classref-method
  271. :ref:`Vector3<class_Vector3>` **get_shortest_axis**\ (\ ) |const| :ref:`🔗<class_AABB_method_get_shortest_axis>`
  272. Returns the shortest normalized axis of this bounding box's :ref:`size<class_AABB_property_size>`, as a :ref:`Vector3<class_Vector3>` (:ref:`Vector3.RIGHT<class_Vector3_constant_RIGHT>`, :ref:`Vector3.UP<class_Vector3_constant_UP>`, or :ref:`Vector3.BACK<class_Vector3_constant_BACK>`).
  273. .. tabs::
  274. .. code-tab:: gdscript
  275. var box = AABB(Vector3(0, 0, 0), Vector3(2, 4, 8))
  276. print(box.get_shortest_axis()) # Prints (1, 0, 0)
  277. print(box.get_shortest_axis_index()) # Prints 0
  278. print(box.get_shortest_axis_size()) # Prints 2
  279. .. code-tab:: csharp
  280. var box = new Aabb(new Vector3(0, 0, 0), new Vector3(2, 4, 8));
  281. GD.Print(box.GetShortestAxis()); // Prints (1, 0, 0)
  282. GD.Print(box.GetShortestAxisIndex()); // Prints 0
  283. GD.Print(box.GetShortestAxisSize()); // Prints 2
  284. See also :ref:`get_shortest_axis_index<class_AABB_method_get_shortest_axis_index>` and :ref:`get_shortest_axis_size<class_AABB_method_get_shortest_axis_size>`.
  285. .. rst-class:: classref-item-separator
  286. ----
  287. .. _class_AABB_method_get_shortest_axis_index:
  288. .. rst-class:: classref-method
  289. :ref:`int<class_int>` **get_shortest_axis_index**\ (\ ) |const| :ref:`🔗<class_AABB_method_get_shortest_axis_index>`
  290. Returns the index to the shortest axis of this bounding box's :ref:`size<class_AABB_property_size>` (see :ref:`Vector3.AXIS_X<class_Vector3_constant_AXIS_X>`, :ref:`Vector3.AXIS_Y<class_Vector3_constant_AXIS_Y>`, and :ref:`Vector3.AXIS_Z<class_Vector3_constant_AXIS_Z>`).
  291. For an example, see :ref:`get_shortest_axis<class_AABB_method_get_shortest_axis>`.
  292. .. rst-class:: classref-item-separator
  293. ----
  294. .. _class_AABB_method_get_shortest_axis_size:
  295. .. rst-class:: classref-method
  296. :ref:`float<class_float>` **get_shortest_axis_size**\ (\ ) |const| :ref:`🔗<class_AABB_method_get_shortest_axis_size>`
  297. Returns the shortest dimension of this bounding box's :ref:`size<class_AABB_property_size>`.
  298. For an example, see :ref:`get_shortest_axis<class_AABB_method_get_shortest_axis>`.
  299. .. rst-class:: classref-item-separator
  300. ----
  301. .. _class_AABB_method_get_support:
  302. .. rst-class:: classref-method
  303. :ref:`Vector3<class_Vector3>` **get_support**\ (\ direction\: :ref:`Vector3<class_Vector3>`\ ) |const| :ref:`🔗<class_AABB_method_get_support>`
  304. Returns the vertex's position of this bounding box that's the farthest in the given direction. This point is commonly known as the support point in collision detection algorithms.
  305. .. rst-class:: classref-item-separator
  306. ----
  307. .. _class_AABB_method_get_volume:
  308. .. rst-class:: classref-method
  309. :ref:`float<class_float>` **get_volume**\ (\ ) |const| :ref:`🔗<class_AABB_method_get_volume>`
  310. Returns the bounding box's volume. This is equivalent to ``size.x * size.y * size.z``. See also :ref:`has_volume<class_AABB_method_has_volume>`.
  311. .. rst-class:: classref-item-separator
  312. ----
  313. .. _class_AABB_method_grow:
  314. .. rst-class:: classref-method
  315. :ref:`AABB<class_AABB>` **grow**\ (\ by\: :ref:`float<class_float>`\ ) |const| :ref:`🔗<class_AABB_method_grow>`
  316. Returns a copy of this bounding box extended on all sides by the given amount ``by``. A negative amount shrinks the box instead.
  317. .. tabs::
  318. .. code-tab:: gdscript
  319. var a = AABB(Vector3(4, 4, 4), Vector3(8, 8, 8)).grow(4)
  320. print(a.position) # Prints (0, 0, 0)
  321. print(a.size) # Prints (16, 16, 16)
  322. var b = AABB(Vector3(0, 0, 0), Vector3(8, 4, 2)).grow(2)
  323. print(b.position) # Prints (-2, -2, -2)
  324. print(b.size) # Prints (12, 8, 6)
  325. .. code-tab:: csharp
  326. var a = new Aabb(new Vector3(4, 4, 4), new Vector3(8, 8, 8)).Grow(4);
  327. GD.Print(a.Position); // Prints (0, 0, 0)
  328. GD.Print(a.Size); // Prints (16, 16, 16)
  329. var b = new Aabb(new Vector3(0, 0, 0), new Vector3(8, 4, 2)).Grow(2);
  330. GD.Print(b.Position); // Prints (-2, -2, -2)
  331. GD.Print(b.Size); // Prints (12, 8, 6)
  332. .. rst-class:: classref-item-separator
  333. ----
  334. .. _class_AABB_method_has_point:
  335. .. rst-class:: classref-method
  336. :ref:`bool<class_bool>` **has_point**\ (\ point\: :ref:`Vector3<class_Vector3>`\ ) |const| :ref:`🔗<class_AABB_method_has_point>`
  337. Returns ``true`` if the bounding box contains the given ``point``. By convention, points exactly on the right, top, and front sides are **not** included.
  338. \ **Note:** This method is not reliable for **AABB** with a *negative* :ref:`size<class_AABB_property_size>`. Use :ref:`abs<class_AABB_method_abs>` first to get a valid bounding box.
  339. .. rst-class:: classref-item-separator
  340. ----
  341. .. _class_AABB_method_has_surface:
  342. .. rst-class:: classref-method
  343. :ref:`bool<class_bool>` **has_surface**\ (\ ) |const| :ref:`🔗<class_AABB_method_has_surface>`
  344. Returns ``true`` if this bounding box has a surface or a length, that is, at least one component of :ref:`size<class_AABB_property_size>` is greater than ``0``. Otherwise, returns ``false``.
  345. .. rst-class:: classref-item-separator
  346. ----
  347. .. _class_AABB_method_has_volume:
  348. .. rst-class:: classref-method
  349. :ref:`bool<class_bool>` **has_volume**\ (\ ) |const| :ref:`🔗<class_AABB_method_has_volume>`
  350. Returns ``true`` if this bounding box's width, height, and depth are all positive. See also :ref:`get_volume<class_AABB_method_get_volume>`.
  351. .. rst-class:: classref-item-separator
  352. ----
  353. .. _class_AABB_method_intersection:
  354. .. rst-class:: classref-method
  355. :ref:`AABB<class_AABB>` **intersection**\ (\ with\: :ref:`AABB<class_AABB>`\ ) |const| :ref:`🔗<class_AABB_method_intersection>`
  356. Returns the intersection between this bounding box and ``with``. If the boxes do not intersect, returns an empty **AABB**. If the boxes intersect at the edge, returns a flat **AABB** with no volume (see :ref:`has_surface<class_AABB_method_has_surface>` and :ref:`has_volume<class_AABB_method_has_volume>`).
  357. .. tabs::
  358. .. code-tab:: gdscript
  359. var box1 = AABB(Vector3(0, 0, 0), Vector3(5, 2, 8))
  360. var box2 = AABB(Vector3(2, 0, 2), Vector3(8, 4, 4))
  361. var intersection = box1.intersection(box2)
  362. print(intersection.position) # Prints (2, 0, 2)
  363. print(intersection.size) # Prints (3, 2, 4)
  364. .. code-tab:: csharp
  365. var box1 = new Aabb(new Vector3(0, 0, 0), new Vector3(5, 2, 8));
  366. var box2 = new Aabb(new Vector3(2, 0, 2), new Vector3(8, 4, 4));
  367. var intersection = box1.Intersection(box2);
  368. GD.Print(intersection.Position); // Prints (2, 0, 2)
  369. GD.Print(intersection.Size); // Prints (3, 2, 4)
  370. \ **Note:** If you only need to know whether two bounding boxes are intersecting, use :ref:`intersects<class_AABB_method_intersects>`, instead.
  371. .. rst-class:: classref-item-separator
  372. ----
  373. .. _class_AABB_method_intersects:
  374. .. rst-class:: classref-method
  375. :ref:`bool<class_bool>` **intersects**\ (\ with\: :ref:`AABB<class_AABB>`\ ) |const| :ref:`🔗<class_AABB_method_intersects>`
  376. Returns ``true`` if this bounding box overlaps with the box ``with``. The edges of both boxes are *always* excluded.
  377. .. rst-class:: classref-item-separator
  378. ----
  379. .. _class_AABB_method_intersects_plane:
  380. .. rst-class:: classref-method
  381. :ref:`bool<class_bool>` **intersects_plane**\ (\ plane\: :ref:`Plane<class_Plane>`\ ) |const| :ref:`🔗<class_AABB_method_intersects_plane>`
  382. Returns ``true`` if this bounding box is on both sides of the given ``plane``.
  383. .. rst-class:: classref-item-separator
  384. ----
  385. .. _class_AABB_method_intersects_ray:
  386. .. rst-class:: classref-method
  387. :ref:`Variant<class_Variant>` **intersects_ray**\ (\ from\: :ref:`Vector3<class_Vector3>`, dir\: :ref:`Vector3<class_Vector3>`\ ) |const| :ref:`🔗<class_AABB_method_intersects_ray>`
  388. Returns the first point where this bounding box and the given ray intersect, as a :ref:`Vector3<class_Vector3>`. If no intersection occurs, returns ``null``.
  389. The ray begin at ``from``, faces ``dir`` and extends towards infinity.
  390. .. rst-class:: classref-item-separator
  391. ----
  392. .. _class_AABB_method_intersects_segment:
  393. .. rst-class:: classref-method
  394. :ref:`Variant<class_Variant>` **intersects_segment**\ (\ from\: :ref:`Vector3<class_Vector3>`, to\: :ref:`Vector3<class_Vector3>`\ ) |const| :ref:`🔗<class_AABB_method_intersects_segment>`
  395. Returns the first point where this bounding box and the given segment intersect, as a :ref:`Vector3<class_Vector3>`. If no intersection occurs, returns ``null``.
  396. The segment begins at ``from`` and ends at ``to``.
  397. .. rst-class:: classref-item-separator
  398. ----
  399. .. _class_AABB_method_is_equal_approx:
  400. .. rst-class:: classref-method
  401. :ref:`bool<class_bool>` **is_equal_approx**\ (\ aabb\: :ref:`AABB<class_AABB>`\ ) |const| :ref:`🔗<class_AABB_method_is_equal_approx>`
  402. Returns ``true`` if this bounding box and ``aabb`` are approximately equal, by calling :ref:`Vector3.is_equal_approx<class_Vector3_method_is_equal_approx>` on the :ref:`position<class_AABB_property_position>` and the :ref:`size<class_AABB_property_size>`.
  403. .. rst-class:: classref-item-separator
  404. ----
  405. .. _class_AABB_method_is_finite:
  406. .. rst-class:: classref-method
  407. :ref:`bool<class_bool>` **is_finite**\ (\ ) |const| :ref:`🔗<class_AABB_method_is_finite>`
  408. Returns ``true`` if this bounding box's values are finite, by calling :ref:`Vector3.is_finite<class_Vector3_method_is_finite>` on the :ref:`position<class_AABB_property_position>` and the :ref:`size<class_AABB_property_size>`.
  409. .. rst-class:: classref-item-separator
  410. ----
  411. .. _class_AABB_method_merge:
  412. .. rst-class:: classref-method
  413. :ref:`AABB<class_AABB>` **merge**\ (\ with\: :ref:`AABB<class_AABB>`\ ) |const| :ref:`🔗<class_AABB_method_merge>`
  414. Returns an **AABB** that encloses both this bounding box and ``with`` around the edges. See also :ref:`encloses<class_AABB_method_encloses>`.
  415. .. rst-class:: classref-section-separator
  416. ----
  417. .. rst-class:: classref-descriptions-group
  418. Operator Descriptions
  419. ---------------------
  420. .. _class_AABB_operator_neq_AABB:
  421. .. rst-class:: classref-operator
  422. :ref:`bool<class_bool>` **operator !=**\ (\ right\: :ref:`AABB<class_AABB>`\ ) :ref:`🔗<class_AABB_operator_neq_AABB>`
  423. Returns ``true`` if the :ref:`position<class_AABB_property_position>` or :ref:`size<class_AABB_property_size>` of both bounding boxes are not equal.
  424. \ **Note:** Due to floating-point precision errors, consider using :ref:`is_equal_approx<class_AABB_method_is_equal_approx>` instead, which is more reliable.
  425. .. rst-class:: classref-item-separator
  426. ----
  427. .. _class_AABB_operator_mul_Transform3D:
  428. .. rst-class:: classref-operator
  429. :ref:`AABB<class_AABB>` **operator ***\ (\ right\: :ref:`Transform3D<class_Transform3D>`\ ) :ref:`🔗<class_AABB_operator_mul_Transform3D>`
  430. Inversely transforms (multiplies) the **AABB** by the given :ref:`Transform3D<class_Transform3D>` transformation matrix, under the assumption that the transformation basis is orthonormal (i.e. rotation/reflection is fine, scaling/skew is not).
  431. \ ``aabb * transform`` is equivalent to ``transform.inverse() * aabb``. See :ref:`Transform3D.inverse<class_Transform3D_method_inverse>`.
  432. For transforming by inverse of an affine transformation (e.g. with scaling) ``transform.affine_inverse() * aabb`` can be used instead. See :ref:`Transform3D.affine_inverse<class_Transform3D_method_affine_inverse>`.
  433. .. rst-class:: classref-item-separator
  434. ----
  435. .. _class_AABB_operator_eq_AABB:
  436. .. rst-class:: classref-operator
  437. :ref:`bool<class_bool>` **operator ==**\ (\ right\: :ref:`AABB<class_AABB>`\ ) :ref:`🔗<class_AABB_operator_eq_AABB>`
  438. Returns ``true`` if both :ref:`position<class_AABB_property_position>` and :ref:`size<class_AABB_property_size>` of the bounding boxes are exactly equal, respectively.
  439. \ **Note:** Due to floating-point precision errors, consider using :ref:`is_equal_approx<class_AABB_method_is_equal_approx>` instead, which is more reliable.
  440. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  441. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  442. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  443. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  444. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  445. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  446. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`
  447. .. |void| replace:: :abbr:`void (No return value.)`