polynomials_on_simplices.geometry.proximity.aabb module

Routines for dealing with axis aligned bounding boxes (AABB).

An AABB is represented with two n:d vectors giving the min and max point of the AABB, i.e., aabb = (min, max) = ((x_min, y_min, z_min), (x_max, y_max, z_max)) (for an AABB in 3D).

corner(aabb, i)[source]

Get the i:th corner of the AABB. Corners are ordered based on their x_n coordinate, with the x_{n-1} coordinate as first tiebreaker, x_{n-2} coordinate as second tiebreaker, and so on. For example the corners of a 3D AABB are ordered on their z-value, with y-value as first tiebreaker, and x-value as second tiebreaker.

Parameters:
  • aabb (Pair of n-dimensional vectors) – AABB defined by its min and max point.
  • i – Index of the corner (in the range 0, 1, …, 2^n-1 where n is the dimension of the AABB).
Returns:

AABB corner (nD vector).

create(points)[source]

Create the minimum AABB containing a set of points.

Parameters:points – Array of points (num_of_points by n).
Returns:Minimum AABB including all input points.
diameter(aabb)[source]

Compute the length of the diameter of an AABB.

Parameters:aabb (Pair of n-dimensional vectors) – AABB defined by its min and max point.
Returns:Length of the diameter of the AABB.
dimension(aabb)[source]

Get the dimension of an AABB.

Parameters:aabb (Pair of n-dimensional vectors) – AABB defined by its min and max point.
Returns:Dimension of the AABB.
empty(n=3)[source]

Create an empty AABB.

Parameters:n – Dimension of the AABB.
Returns:Empty AABB.
full(n=3)[source]

Create an AABB covering all of \(\mathbb{R}^n\).

Parameters:n – Dimension of the AABB.
Returns:The AABB containing all of \(\mathbb{R}^n\).

Examples

>>> full(1)
(array([-inf]), array([inf]))
>>> full(2)
(array([-inf, -inf]), array([inf, inf]))
half_diagonal(aabb)[source]

Compute the half-diagonal of an AABB.

Parameters:aabb (Pair of n-dimensional vectors) – AABB defined by its min and max point.
Returns:Half-diagonal of the AABB (vector from the AABB midpoint to the max point).
intersection(aabb1, aabb2)[source]

Compute the intersection of two AABBs.

Parameters:
  • aabb1 – First AABB.
  • aabb2 – Second AABB.
Returns:

Minimum AABB including all points in both aabb1 and aabb2.

is_empty(aabb)[source]

Check if an AABB is empty.

Note

An AABB is empty if max[i] < min[i] for some i in [0, 1, 2]. An AABB with min = max is not considered empty since it contains a single point.

Parameters:aabb (Pair of n-dimensional vectors) – AABB defined by its min and max point.
Returns:True/False depending on whether or not the AABB is empty.
is_equal(aabb1, aabb2, rel_tol=1e-09, abs_tol=1e-07)[source]

Check if two AABBs aabb1 and aabb2 are approximately equal.

The two AABBs are considered equal if the min and max points of the AABBs are componentwise approximately equal. For the componentwise equality check, the standard function math.isclose is used, with the given relative and absolute tolerances.

is_valid(aabb)[source]

Check if an AABB is valid (has valid min and max points, and min[i] <= max[i] for all i in [0, 1, 2]).

Parameters:aabb (Pair of n-dimensional vectors) – AABB defined by its min and max point.
Returns:True/False depending on whether or not the AABB is valid.
midpoint(aabb)[source]

Compute the midpoint of an AABB.

Parameters:aabb (Pair of n-dimensional vectors) – AABB defined by its min and max point.
Returns:Midpoint of the AABB (nd vector).
point_inside(aabb, p)[source]

Check if a point is inside an AABB.

Parameters:
  • aabb (Pair of n-dimensional vectors) – AABB defined by its min and max point.
  • p – Point (n dimensional vector).
Returns:

True/False whether or not the point is inside the AABB.

union(aabb1, aabb2)[source]

Compute the union of two AABBs.

Parameters:
  • aabb1 – First AABB.
  • aabb2 – Second AABB.
Returns:

Minimum AABB including all points in either aabb1 or aabb2.

unit(n=3)[source]

Create the unit AABB (side lengths 1 and with the min point in the origin).

Parameters:n – Dimension of the AABB.
Returns:The unit AABB.
volume(aabb)[source]

Compute the volume of an AABB.

Parameters:aabb (Pair of n-dimensional vectors) – AABB defined by its min and max point.
Returns:Volume of the AABB.