123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778 |
- :github_url: hide
- .. DO NOT EDIT THIS FILE!!!
- .. Generated automatically from Godot engine sources.
- .. Generator: https://github.com/godotengine/godot/tree/master/doc/tools/make_rst.py.
- .. XML source: https://github.com/godotengine/godot/tree/master/doc/classes/AABB.xml.
- .. _class_AABB:
- AABB
- ====
- A 3D axis-aligned bounding box.
- .. rst-class:: classref-introduction-group
- Description
- -----------
- 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.
- 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.
- \ **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.
- \ **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``.
- .. note::
- There are notable differences when using this API with C#. See :ref:`doc_c_sharp_differences` for more information.
- .. rst-class:: classref-introduction-group
- Tutorials
- ---------
- - :doc:`Math documentation index <../tutorials/math/index>`
- - :doc:`Vector math <../tutorials/math/vector_math>`
- - :doc:`Advanced vector math <../tutorials/math/vectors_advanced>`
- .. rst-class:: classref-reftable-group
- Properties
- ----------
- .. table::
- :widths: auto
- +-------------------------------+-----------------------------------------------+----------------------+
- | :ref:`Vector3<class_Vector3>` | :ref:`end<class_AABB_property_end>` | ``Vector3(0, 0, 0)`` |
- +-------------------------------+-----------------------------------------------+----------------------+
- | :ref:`Vector3<class_Vector3>` | :ref:`position<class_AABB_property_position>` | ``Vector3(0, 0, 0)`` |
- +-------------------------------+-----------------------------------------------+----------------------+
- | :ref:`Vector3<class_Vector3>` | :ref:`size<class_AABB_property_size>` | ``Vector3(0, 0, 0)`` |
- +-------------------------------+-----------------------------------------------+----------------------+
- .. rst-class:: classref-reftable-group
- Constructors
- ------------
- .. table::
- :widths: auto
- +-------------------------+--------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`AABB<class_AABB>` | :ref:`AABB<class_AABB_constructor_AABB>`\ (\ ) |
- +-------------------------+--------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`AABB<class_AABB>` | :ref:`AABB<class_AABB_constructor_AABB>`\ (\ from\: :ref:`AABB<class_AABB>`\ ) |
- +-------------------------+--------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`AABB<class_AABB>` | :ref:`AABB<class_AABB_constructor_AABB>`\ (\ position\: :ref:`Vector3<class_Vector3>`, size\: :ref:`Vector3<class_Vector3>`\ ) |
- +-------------------------+--------------------------------------------------------------------------------------------------------------------------------+
- .. rst-class:: classref-reftable-group
- Methods
- -------
- .. table::
- :widths: auto
- +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`AABB<class_AABB>` | :ref:`abs<class_AABB_method_abs>`\ (\ ) |const| |
- +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`bool<class_bool>` | :ref:`encloses<class_AABB_method_encloses>`\ (\ with\: :ref:`AABB<class_AABB>`\ ) |const| |
- +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`AABB<class_AABB>` | :ref:`expand<class_AABB_method_expand>`\ (\ to_point\: :ref:`Vector3<class_Vector3>`\ ) |const| |
- +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Vector3<class_Vector3>` | :ref:`get_center<class_AABB_method_get_center>`\ (\ ) |const| |
- +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Vector3<class_Vector3>` | :ref:`get_endpoint<class_AABB_method_get_endpoint>`\ (\ idx\: :ref:`int<class_int>`\ ) |const| |
- +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Vector3<class_Vector3>` | :ref:`get_longest_axis<class_AABB_method_get_longest_axis>`\ (\ ) |const| |
- +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`int<class_int>` | :ref:`get_longest_axis_index<class_AABB_method_get_longest_axis_index>`\ (\ ) |const| |
- +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`float<class_float>` | :ref:`get_longest_axis_size<class_AABB_method_get_longest_axis_size>`\ (\ ) |const| |
- +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Vector3<class_Vector3>` | :ref:`get_shortest_axis<class_AABB_method_get_shortest_axis>`\ (\ ) |const| |
- +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`int<class_int>` | :ref:`get_shortest_axis_index<class_AABB_method_get_shortest_axis_index>`\ (\ ) |const| |
- +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`float<class_float>` | :ref:`get_shortest_axis_size<class_AABB_method_get_shortest_axis_size>`\ (\ ) |const| |
- +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Vector3<class_Vector3>` | :ref:`get_support<class_AABB_method_get_support>`\ (\ direction\: :ref:`Vector3<class_Vector3>`\ ) |const| |
- +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`float<class_float>` | :ref:`get_volume<class_AABB_method_get_volume>`\ (\ ) |const| |
- +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`AABB<class_AABB>` | :ref:`grow<class_AABB_method_grow>`\ (\ by\: :ref:`float<class_float>`\ ) |const| |
- +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`bool<class_bool>` | :ref:`has_point<class_AABB_method_has_point>`\ (\ point\: :ref:`Vector3<class_Vector3>`\ ) |const| |
- +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`bool<class_bool>` | :ref:`has_surface<class_AABB_method_has_surface>`\ (\ ) |const| |
- +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`bool<class_bool>` | :ref:`has_volume<class_AABB_method_has_volume>`\ (\ ) |const| |
- +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`AABB<class_AABB>` | :ref:`intersection<class_AABB_method_intersection>`\ (\ with\: :ref:`AABB<class_AABB>`\ ) |const| |
- +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`bool<class_bool>` | :ref:`intersects<class_AABB_method_intersects>`\ (\ with\: :ref:`AABB<class_AABB>`\ ) |const| |
- +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`bool<class_bool>` | :ref:`intersects_plane<class_AABB_method_intersects_plane>`\ (\ plane\: :ref:`Plane<class_Plane>`\ ) |const| |
- +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Variant<class_Variant>` | :ref:`intersects_ray<class_AABB_method_intersects_ray>`\ (\ from\: :ref:`Vector3<class_Vector3>`, dir\: :ref:`Vector3<class_Vector3>`\ ) |const| |
- +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Variant<class_Variant>` | :ref:`intersects_segment<class_AABB_method_intersects_segment>`\ (\ from\: :ref:`Vector3<class_Vector3>`, to\: :ref:`Vector3<class_Vector3>`\ ) |const| |
- +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`bool<class_bool>` | :ref:`is_equal_approx<class_AABB_method_is_equal_approx>`\ (\ aabb\: :ref:`AABB<class_AABB>`\ ) |const| |
- +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`bool<class_bool>` | :ref:`is_finite<class_AABB_method_is_finite>`\ (\ ) |const| |
- +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`AABB<class_AABB>` | :ref:`merge<class_AABB_method_merge>`\ (\ with\: :ref:`AABB<class_AABB>`\ ) |const| |
- +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
- .. rst-class:: classref-reftable-group
- Operators
- ---------
- .. table::
- :widths: auto
- +-------------------------+-------------------------------------------------------------------------------------------------------------+
- | :ref:`bool<class_bool>` | :ref:`operator !=<class_AABB_operator_neq_AABB>`\ (\ right\: :ref:`AABB<class_AABB>`\ ) |
- +-------------------------+-------------------------------------------------------------------------------------------------------------+
- | :ref:`AABB<class_AABB>` | :ref:`operator *<class_AABB_operator_mul_Transform3D>`\ (\ right\: :ref:`Transform3D<class_Transform3D>`\ ) |
- +-------------------------+-------------------------------------------------------------------------------------------------------------+
- | :ref:`bool<class_bool>` | :ref:`operator ==<class_AABB_operator_eq_AABB>`\ (\ right\: :ref:`AABB<class_AABB>`\ ) |
- +-------------------------+-------------------------------------------------------------------------------------------------------------+
- .. rst-class:: classref-section-separator
- ----
- .. rst-class:: classref-descriptions-group
- Property Descriptions
- ---------------------
- .. _class_AABB_property_end:
- .. rst-class:: classref-property
- :ref:`Vector3<class_Vector3>` **end** = ``Vector3(0, 0, 0)`` :ref:`🔗<class_AABB_property_end>`
- 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>`.
- .. rst-class:: classref-item-separator
- ----
- .. _class_AABB_property_position:
- .. rst-class:: classref-property
- :ref:`Vector3<class_Vector3>` **position** = ``Vector3(0, 0, 0)`` :ref:`🔗<class_AABB_property_position>`
- The origin point. This is usually the corner on the bottom-left and back of the bounding box.
- .. rst-class:: classref-item-separator
- ----
- .. _class_AABB_property_size:
- .. rst-class:: classref-property
- :ref:`Vector3<class_Vector3>` **size** = ``Vector3(0, 0, 0)`` :ref:`🔗<class_AABB_property_size>`
- 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.
- \ **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>`.
- .. rst-class:: classref-section-separator
- ----
- .. rst-class:: classref-descriptions-group
- Constructor Descriptions
- ------------------------
- .. _class_AABB_constructor_AABB:
- .. rst-class:: classref-constructor
- :ref:`AABB<class_AABB>` **AABB**\ (\ ) :ref:`🔗<class_AABB_constructor_AABB>`
- 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>`.
- .. rst-class:: classref-item-separator
- ----
- .. rst-class:: classref-constructor
- :ref:`AABB<class_AABB>` **AABB**\ (\ from\: :ref:`AABB<class_AABB>`\ )
- Constructs an **AABB** as a copy of the given **AABB**.
- .. rst-class:: classref-item-separator
- ----
- .. rst-class:: classref-constructor
- :ref:`AABB<class_AABB>` **AABB**\ (\ position\: :ref:`Vector3<class_Vector3>`, size\: :ref:`Vector3<class_Vector3>`\ )
- Constructs an **AABB** by ``position`` and ``size``.
- .. rst-class:: classref-section-separator
- ----
- .. rst-class:: classref-descriptions-group
- Method Descriptions
- -------------------
- .. _class_AABB_method_abs:
- .. rst-class:: classref-method
- :ref:`AABB<class_AABB>` **abs**\ (\ ) |const| :ref:`🔗<class_AABB_method_abs>`
- Returns an **AABB** equivalent to this bounding box, with its width, height, and depth modified to be non-negative values.
- .. tabs::
- .. code-tab:: gdscript
- var box = AABB(Vector3(5, 0, 5), Vector3(-20, -10, -5))
- var absolute = box.abs()
- print(absolute.position) # Prints (-15, -10, 0)
- print(absolute.size) # Prints (20, 10, 5)
- .. code-tab:: csharp
- var box = new Aabb(new Vector3(5, 0, 5), new Vector3(-20, -10, -5));
- var absolute = box.Abs();
- GD.Print(absolute.Position); // Prints (-15, -10, 0)
- GD.Print(absolute.Size); // Prints (20, 10, 5)
- \ **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``.
- .. rst-class:: classref-item-separator
- ----
- .. _class_AABB_method_encloses:
- .. rst-class:: classref-method
- :ref:`bool<class_bool>` **encloses**\ (\ with\: :ref:`AABB<class_AABB>`\ ) |const| :ref:`🔗<class_AABB_method_encloses>`
- Returns ``true`` if this bounding box *completely* encloses the ``with`` box. The edges of both boxes are included.
- .. tabs::
- .. code-tab:: gdscript
- var a = AABB(Vector3(0, 0, 0), Vector3(4, 4, 4))
- var b = AABB(Vector3(1, 1, 1), Vector3(3, 3, 3))
- var c = AABB(Vector3(2, 2, 2), Vector3(8, 8, 8))
-
- print(a.encloses(a)) # Prints true
- print(a.encloses(b)) # Prints true
- print(a.encloses(c)) # Prints false
- .. code-tab:: csharp
- var a = new Aabb(new Vector3(0, 0, 0), new Vector3(4, 4, 4));
- var b = new Aabb(new Vector3(1, 1, 1), new Vector3(3, 3, 3));
- var c = new Aabb(new Vector3(2, 2, 2), new Vector3(8, 8, 8));
-
- GD.Print(a.Encloses(a)); // Prints True
- GD.Print(a.Encloses(b)); // Prints True
- GD.Print(a.Encloses(c)); // Prints False
- .. rst-class:: classref-item-separator
- ----
- .. _class_AABB_method_expand:
- .. rst-class:: classref-method
- :ref:`AABB<class_AABB>` **expand**\ (\ to_point\: :ref:`Vector3<class_Vector3>`\ ) |const| :ref:`🔗<class_AABB_method_expand>`
- Returns a copy of this bounding box expanded to align the edges with the given ``to_point``, if necessary.
- .. tabs::
- .. code-tab:: gdscript
- var box = AABB(Vector3(0, 0, 0), Vector3(5, 2, 5))
-
- box = box.expand(Vector3(10, 0, 0))
- print(box.position) # Prints (0, 0, 0)
- print(box.size) # Prints (10, 2, 5)
-
- box = box.expand(Vector3(-5, 0, 5))
- print(box.position) # Prints (-5, 0, 0)
- print(box.size) # Prints (15, 2, 5)
- .. code-tab:: csharp
- var box = new Aabb(new Vector3(0, 0, 0), new Vector3(5, 2, 5));
-
- box = box.Expand(new Vector3(10, 0, 0));
- GD.Print(box.Position); // Prints (0, 0, 0)
- GD.Print(box.Size); // Prints (10, 2, 5)
-
- box = box.Expand(new Vector3(-5, 0, 5));
- GD.Print(box.Position); // Prints (-5, 0, 0)
- GD.Print(box.Size); // Prints (15, 2, 5)
- .. rst-class:: classref-item-separator
- ----
- .. _class_AABB_method_get_center:
- .. rst-class:: classref-method
- :ref:`Vector3<class_Vector3>` **get_center**\ (\ ) |const| :ref:`🔗<class_AABB_method_get_center>`
- Returns the center point of the bounding box. This is the same as ``position + (size / 2.0)``.
- .. rst-class:: classref-item-separator
- ----
- .. _class_AABB_method_get_endpoint:
- .. rst-class:: classref-method
- :ref:`Vector3<class_Vector3>` **get_endpoint**\ (\ idx\: :ref:`int<class_int>`\ ) |const| :ref:`🔗<class_AABB_method_get_endpoint>`
- 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>`.
- .. rst-class:: classref-item-separator
- ----
- .. _class_AABB_method_get_longest_axis:
- .. rst-class:: classref-method
- :ref:`Vector3<class_Vector3>` **get_longest_axis**\ (\ ) |const| :ref:`🔗<class_AABB_method_get_longest_axis>`
- 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>`).
- .. tabs::
- .. code-tab:: gdscript
- var box = AABB(Vector3(0, 0, 0), Vector3(2, 4, 8))
-
- print(box.get_longest_axis()) # Prints (0, 0, 1)
- print(box.get_longest_axis_index()) # Prints 2
- print(box.get_longest_axis_size()) # Prints 8
- .. code-tab:: csharp
- var box = new Aabb(new Vector3(0, 0, 0), new Vector3(2, 4, 8));
-
- GD.Print(box.GetLongestAxis()); // Prints (0, 0, 1)
- GD.Print(box.GetLongestAxisIndex()); // Prints 2
- GD.Print(box.GetLongestAxisSize()); // Prints 8
- 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>`.
- .. rst-class:: classref-item-separator
- ----
- .. _class_AABB_method_get_longest_axis_index:
- .. rst-class:: classref-method
- :ref:`int<class_int>` **get_longest_axis_index**\ (\ ) |const| :ref:`🔗<class_AABB_method_get_longest_axis_index>`
- 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>`).
- For an example, see :ref:`get_longest_axis<class_AABB_method_get_longest_axis>`.
- .. rst-class:: classref-item-separator
- ----
- .. _class_AABB_method_get_longest_axis_size:
- .. rst-class:: classref-method
- :ref:`float<class_float>` **get_longest_axis_size**\ (\ ) |const| :ref:`🔗<class_AABB_method_get_longest_axis_size>`
- Returns the longest dimension of this bounding box's :ref:`size<class_AABB_property_size>`.
- For an example, see :ref:`get_longest_axis<class_AABB_method_get_longest_axis>`.
- .. rst-class:: classref-item-separator
- ----
- .. _class_AABB_method_get_shortest_axis:
- .. rst-class:: classref-method
- :ref:`Vector3<class_Vector3>` **get_shortest_axis**\ (\ ) |const| :ref:`🔗<class_AABB_method_get_shortest_axis>`
- 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>`).
- .. tabs::
- .. code-tab:: gdscript
- var box = AABB(Vector3(0, 0, 0), Vector3(2, 4, 8))
-
- print(box.get_shortest_axis()) # Prints (1, 0, 0)
- print(box.get_shortest_axis_index()) # Prints 0
- print(box.get_shortest_axis_size()) # Prints 2
- .. code-tab:: csharp
- var box = new Aabb(new Vector3(0, 0, 0), new Vector3(2, 4, 8));
-
- GD.Print(box.GetShortestAxis()); // Prints (1, 0, 0)
- GD.Print(box.GetShortestAxisIndex()); // Prints 0
- GD.Print(box.GetShortestAxisSize()); // Prints 2
- 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>`.
- .. rst-class:: classref-item-separator
- ----
- .. _class_AABB_method_get_shortest_axis_index:
- .. rst-class:: classref-method
- :ref:`int<class_int>` **get_shortest_axis_index**\ (\ ) |const| :ref:`🔗<class_AABB_method_get_shortest_axis_index>`
- 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>`).
- For an example, see :ref:`get_shortest_axis<class_AABB_method_get_shortest_axis>`.
- .. rst-class:: classref-item-separator
- ----
- .. _class_AABB_method_get_shortest_axis_size:
- .. rst-class:: classref-method
- :ref:`float<class_float>` **get_shortest_axis_size**\ (\ ) |const| :ref:`🔗<class_AABB_method_get_shortest_axis_size>`
- Returns the shortest dimension of this bounding box's :ref:`size<class_AABB_property_size>`.
- For an example, see :ref:`get_shortest_axis<class_AABB_method_get_shortest_axis>`.
- .. rst-class:: classref-item-separator
- ----
- .. _class_AABB_method_get_support:
- .. rst-class:: classref-method
- :ref:`Vector3<class_Vector3>` **get_support**\ (\ direction\: :ref:`Vector3<class_Vector3>`\ ) |const| :ref:`🔗<class_AABB_method_get_support>`
- 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.
- .. rst-class:: classref-item-separator
- ----
- .. _class_AABB_method_get_volume:
- .. rst-class:: classref-method
- :ref:`float<class_float>` **get_volume**\ (\ ) |const| :ref:`🔗<class_AABB_method_get_volume>`
- 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>`.
- .. rst-class:: classref-item-separator
- ----
- .. _class_AABB_method_grow:
- .. rst-class:: classref-method
- :ref:`AABB<class_AABB>` **grow**\ (\ by\: :ref:`float<class_float>`\ ) |const| :ref:`🔗<class_AABB_method_grow>`
- Returns a copy of this bounding box extended on all sides by the given amount ``by``. A negative amount shrinks the box instead.
- .. tabs::
- .. code-tab:: gdscript
- var a = AABB(Vector3(4, 4, 4), Vector3(8, 8, 8)).grow(4)
- print(a.position) # Prints (0, 0, 0)
- print(a.size) # Prints (16, 16, 16)
-
- var b = AABB(Vector3(0, 0, 0), Vector3(8, 4, 2)).grow(2)
- print(b.position) # Prints (-2, -2, -2)
- print(b.size) # Prints (12, 8, 6)
- .. code-tab:: csharp
- var a = new Aabb(new Vector3(4, 4, 4), new Vector3(8, 8, 8)).Grow(4);
- GD.Print(a.Position); // Prints (0, 0, 0)
- GD.Print(a.Size); // Prints (16, 16, 16)
-
- var b = new Aabb(new Vector3(0, 0, 0), new Vector3(8, 4, 2)).Grow(2);
- GD.Print(b.Position); // Prints (-2, -2, -2)
- GD.Print(b.Size); // Prints (12, 8, 6)
- .. rst-class:: classref-item-separator
- ----
- .. _class_AABB_method_has_point:
- .. rst-class:: classref-method
- :ref:`bool<class_bool>` **has_point**\ (\ point\: :ref:`Vector3<class_Vector3>`\ ) |const| :ref:`🔗<class_AABB_method_has_point>`
- Returns ``true`` if the bounding box contains the given ``point``. By convention, points exactly on the right, top, and front sides are **not** included.
- \ **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.
- .. rst-class:: classref-item-separator
- ----
- .. _class_AABB_method_has_surface:
- .. rst-class:: classref-method
- :ref:`bool<class_bool>` **has_surface**\ (\ ) |const| :ref:`🔗<class_AABB_method_has_surface>`
- 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``.
- .. rst-class:: classref-item-separator
- ----
- .. _class_AABB_method_has_volume:
- .. rst-class:: classref-method
- :ref:`bool<class_bool>` **has_volume**\ (\ ) |const| :ref:`🔗<class_AABB_method_has_volume>`
- Returns ``true`` if this bounding box's width, height, and depth are all positive. See also :ref:`get_volume<class_AABB_method_get_volume>`.
- .. rst-class:: classref-item-separator
- ----
- .. _class_AABB_method_intersection:
- .. rst-class:: classref-method
- :ref:`AABB<class_AABB>` **intersection**\ (\ with\: :ref:`AABB<class_AABB>`\ ) |const| :ref:`🔗<class_AABB_method_intersection>`
- 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>`).
- .. tabs::
- .. code-tab:: gdscript
- var box1 = AABB(Vector3(0, 0, 0), Vector3(5, 2, 8))
- var box2 = AABB(Vector3(2, 0, 2), Vector3(8, 4, 4))
-
- var intersection = box1.intersection(box2)
- print(intersection.position) # Prints (2, 0, 2)
- print(intersection.size) # Prints (3, 2, 4)
- .. code-tab:: csharp
- var box1 = new Aabb(new Vector3(0, 0, 0), new Vector3(5, 2, 8));
- var box2 = new Aabb(new Vector3(2, 0, 2), new Vector3(8, 4, 4));
-
- var intersection = box1.Intersection(box2);
- GD.Print(intersection.Position); // Prints (2, 0, 2)
- GD.Print(intersection.Size); // Prints (3, 2, 4)
- \ **Note:** If you only need to know whether two bounding boxes are intersecting, use :ref:`intersects<class_AABB_method_intersects>`, instead.
- .. rst-class:: classref-item-separator
- ----
- .. _class_AABB_method_intersects:
- .. rst-class:: classref-method
- :ref:`bool<class_bool>` **intersects**\ (\ with\: :ref:`AABB<class_AABB>`\ ) |const| :ref:`🔗<class_AABB_method_intersects>`
- Returns ``true`` if this bounding box overlaps with the box ``with``. The edges of both boxes are *always* excluded.
- .. rst-class:: classref-item-separator
- ----
- .. _class_AABB_method_intersects_plane:
- .. rst-class:: classref-method
- :ref:`bool<class_bool>` **intersects_plane**\ (\ plane\: :ref:`Plane<class_Plane>`\ ) |const| :ref:`🔗<class_AABB_method_intersects_plane>`
- Returns ``true`` if this bounding box is on both sides of the given ``plane``.
- .. rst-class:: classref-item-separator
- ----
- .. _class_AABB_method_intersects_ray:
- .. rst-class:: classref-method
- :ref:`Variant<class_Variant>` **intersects_ray**\ (\ from\: :ref:`Vector3<class_Vector3>`, dir\: :ref:`Vector3<class_Vector3>`\ ) |const| :ref:`🔗<class_AABB_method_intersects_ray>`
- 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``.
- The ray begin at ``from``, faces ``dir`` and extends towards infinity.
- .. rst-class:: classref-item-separator
- ----
- .. _class_AABB_method_intersects_segment:
- .. rst-class:: classref-method
- :ref:`Variant<class_Variant>` **intersects_segment**\ (\ from\: :ref:`Vector3<class_Vector3>`, to\: :ref:`Vector3<class_Vector3>`\ ) |const| :ref:`🔗<class_AABB_method_intersects_segment>`
- 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``.
- The segment begins at ``from`` and ends at ``to``.
- .. rst-class:: classref-item-separator
- ----
- .. _class_AABB_method_is_equal_approx:
- .. rst-class:: classref-method
- :ref:`bool<class_bool>` **is_equal_approx**\ (\ aabb\: :ref:`AABB<class_AABB>`\ ) |const| :ref:`🔗<class_AABB_method_is_equal_approx>`
- 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>`.
- .. rst-class:: classref-item-separator
- ----
- .. _class_AABB_method_is_finite:
- .. rst-class:: classref-method
- :ref:`bool<class_bool>` **is_finite**\ (\ ) |const| :ref:`🔗<class_AABB_method_is_finite>`
- 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>`.
- .. rst-class:: classref-item-separator
- ----
- .. _class_AABB_method_merge:
- .. rst-class:: classref-method
- :ref:`AABB<class_AABB>` **merge**\ (\ with\: :ref:`AABB<class_AABB>`\ ) |const| :ref:`🔗<class_AABB_method_merge>`
- Returns an **AABB** that encloses both this bounding box and ``with`` around the edges. See also :ref:`encloses<class_AABB_method_encloses>`.
- .. rst-class:: classref-section-separator
- ----
- .. rst-class:: classref-descriptions-group
- Operator Descriptions
- ---------------------
- .. _class_AABB_operator_neq_AABB:
- .. rst-class:: classref-operator
- :ref:`bool<class_bool>` **operator !=**\ (\ right\: :ref:`AABB<class_AABB>`\ ) :ref:`🔗<class_AABB_operator_neq_AABB>`
- Returns ``true`` if the :ref:`position<class_AABB_property_position>` or :ref:`size<class_AABB_property_size>` of both bounding boxes are not equal.
- \ **Note:** Due to floating-point precision errors, consider using :ref:`is_equal_approx<class_AABB_method_is_equal_approx>` instead, which is more reliable.
- .. rst-class:: classref-item-separator
- ----
- .. _class_AABB_operator_mul_Transform3D:
- .. rst-class:: classref-operator
- :ref:`AABB<class_AABB>` **operator ***\ (\ right\: :ref:`Transform3D<class_Transform3D>`\ ) :ref:`🔗<class_AABB_operator_mul_Transform3D>`
- 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).
- \ ``aabb * transform`` is equivalent to ``transform.inverse() * aabb``. See :ref:`Transform3D.inverse<class_Transform3D_method_inverse>`.
- 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>`.
- .. rst-class:: classref-item-separator
- ----
- .. _class_AABB_operator_eq_AABB:
- .. rst-class:: classref-operator
- :ref:`bool<class_bool>` **operator ==**\ (\ right\: :ref:`AABB<class_AABB>`\ ) :ref:`🔗<class_AABB_operator_eq_AABB>`
- 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.
- \ **Note:** Due to floating-point precision errors, consider using :ref:`is_equal_approx<class_AABB_method_is_equal_approx>` instead, which is more reliable.
- .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
- .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
- .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
- .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
- .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
- .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
- .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`
- .. |void| replace:: :abbr:`void (No return value.)`
|