1.4. Spatial Acceleration

class raysect.core.boundingbox.BoundingBox2D

Axis-aligned 2D bounding box.

Parameters
  • lower (Point2D) – (optional) starting point for lower box corner

  • upper (Point2D) – (optional) starting point for upper box corner

contains()

Returns true if the given 2D point lies inside the bounding box.

Parameters

point (Point2D) – A given test point.

Return type

boolean

extend()

Enlarge this bounding box to enclose the given point.

The resulting bounding box will be larger so as to just enclose the existing bounding box and the new point. This class instance will be edited in place to have the new bounding box dimensions.

Parameters
  • point (Point2D) – the point to use for extending the bounding box.

  • padding (float) – optional padding parameter, gives extra margin around the new point.

extent()

Returns the spatial extend of this bounding box along the given dimension.

Parameters

axis (int) – specifies the axis to return, {0: X axis, 1: Y axis}.

Return type

float

largest_axis()

Find the largest axis of this bounding box.

Returns

an int specifying the longest axis, {0: X axis, 1: Y axis}.

Return type

int

largest_extent()

Find the largest spatial extent across all axes.

Returns

distance along the largest bounding box axis.

Return type

float

lower

The point defining the lower corner of the bounding box.

Return type

Point2D

pad()

Makes the bounding box larger by the specified amount of padding.

Every bounding box axis will end up larger by a factor of 2 x padding.

Parameters

padding (float) – distance to use as padding margin

pad_axis()

Makes the bounding box larger along the specified axis by amount of padding.

The specified bounding box axis will end up larger by a factor of 2 x padding.

Parameters
  • axis (int) – The axis to apply padding to {0: X axis, 1: Y axis}.

  • padding (float) – Distance to use as padding margin.

surface_area()

Returns the surface area of the bounding box.

Return type

float

union()

Union this bounding box instance with the input bounding box.

The resulting bounding box will be larger so as to just enclose both bounding boxes. This class instance will be edited in place to have the new bounding box dimensions.

Parameters

box (BoundingBox2D) – A bounding box instance to union with this bounding box instance.

upper

The point defining the upper corner of the bounding box.

Return type

Point2D

vertices()

Get the list of vertices for this bounding box.

Returns

A list of Point2D’s representing the corners of the bounding box.

Return type

list

class raysect.core.boundingbox.BoundingBox3D

Axis-aligned bounding box.

Represents a bounding box around a primitive’s surface. The points defining the lower and upper corners of the box must be specified in world space.

Axis aligned bounding box ray intersections are extremely fast to evaluate compared to intersections with more general geometry. Prior to testing a primitives hit() method the hit() method of the bounding box is called. If the bounding box is not hit, then the expensive primitive hit() method is avoided.

Combined with a spatial subdivision acceleration structure, the cost of ray- primitive evaluations can be heavily reduced (O(n) -> O(log n)).

For optimal speed the bounding box is aligned with the world space axes. As rays are propagated in world space, co-ordinate transforms can be avoided.

Parameters
  • lower (Point3D) – (optional) starting point for lower box corner

  • upper (Point3D) – (optional) starting point for upper box corner

centre

The point defining the geometric centre of the bounding box.

Return type

Point3D

contains()

Returns true if the given 3D point lies inside the bounding box.

Parameters

point (Point3D) – A given test point.

Return type

boolean

enclosing_sphere()

Returns a BoundingSphere3D guaranteed to enclose the bounding box.

The sphere is centred at the box centre. A small degree of padding is added to avoid numerical accuracy issues.

Returns

A BoundingSphere3D object.

Return type

BoundingSphere3D

extend()

Enlarge this bounding box to enclose the given point.

The resulting bounding box will be larger so as to just enclose the existing bounding box and the new point. This class instance will be edited in place to have the new bounding box dimensions.

Parameters
  • point (Point3D) – the point to use for extending the bounding box.

  • padding (float) – optional padding parameter, gives extra margin around the new point.

extent()

Returns the spatial extend of this bounding box along the given dimension.

Parameters

axis (int) – specifies the axis to return, {0: X axis, 1: Y axis, 2: Z axis}.

Return type

float

full_intersection()

Returns full intersection information for an intersection between a ray and a bounding box.

The first value is a boolean which is true if an intersection has occured, false otherwise. Each intersection with a bounding box will produce two intersections, one on the front and back of the box. The remaining two tuple parameters are floats representing the distance along the ray path to the respective intersections.

Parameters

ray – The ray to test for intersection

Returns

A tuple of intersection parameters, (hit, front_intersection, back_intersection).

Return type

tuple

hit()

Returns true if the ray hits the bounding box.

Parameters

ray (Ray) – The ray to test for intersection.

Return type

boolean

largest_axis()

Find the largest axis of this bounding box.

Returns

an int specifying the longest axis, {0: X axis, 1: Y axis, 2: Z axis}.

Return type

int

largest_extent()

Find the largest spatial extent across all axes.

Returns

distance along the largest bounding box axis.

Return type

float

lower

The point defining the lower corner of the bounding box.

Return type

Point3D

pad()

Makes the bounding box larger by the specified amount of padding.

Every bounding box axis will end up larger by a factor of 2 x padding.

Parameters

padding (float) – distance to use as padding margin

pad_axis()

Makes the bounding box larger along the specified axis by amount of padding.

The specified bounding box axis will end up larger by a factor of 2 x padding.

Parameters
  • axis (int) – The axis to apply padding to {0: X axis, 1: Y axis, 2: Z axis}.

  • padding (float) – Distance to use as padding margin.

surface_area()

Returns the surface area of the bounding box.

Return type

float

union()

Union this bounding box instance with the input bounding box.

The resulting bounding box will be larger so as to just enclose both bounding boxes. This class instance will be edited in place to have the new bounding box dimensions.

Parameters

box (BoundingBox3D) – A bounding box instance to union with this bounding box instance.

upper

The point defining the upper corner of the bounding box.

Return type

Point3D

vertices()

Get the list of vertices for this bounding box.

Returns

A list of Point3D’s representing the corners of the bounding box.

Return type

list

volume()

Returns the volume of the bounding box.

Return type

float

class raysect.core.boundingsphere.BoundingSphere3D

A bounding sphere.

Represents a bounding sphere around a primitive’s surface. The sphere’s centre point and radius must be specified in world space.

Parameters
  • centre (Point3D) – the centre point of the bounding sphere.

  • radius (float) – the radius of the sphere that bounds the primitive.

centre

The point defining the centre of the bounding sphere.

Return type

Point3D

contains()

Returns true if the given 3D point lies inside the bounding sphere.

Parameters

point (Point3D) – A given test point.

Return type

boolean

extend()

Enlarge this bounding box to enclose the given point.

The resulting bounding box will be larger so as to just enclose the existing bounding box and the new point. This class instance will be edited in place to have the new bounding box dimensions.

Parameters
  • point (Point3D) – the point to use for extending the bounding box.

  • padding (float) – optional padding parameter, gives extra margin around the new point.

full_intersection()

Returns full intersection information for an intersection between a ray and a bounding box.

The first value is a boolean which is true if an intersection has occured, false otherwise. Each intersection with a bounding box will produce two intersections, one on the front and back of the box. The remaining two tuple parameters are floats representing the distance along the ray path to the respective intersections.

Parameters

ray – The ray to test for intersection

Returns

A tuple of intersection parameters, (hit, front_intersection, back_intersection).

Return type

tuple

hit()

Returns true if the ray hits the bounding box.

Parameters

ray (Ray) – The ray to test for intersection.

Return type

boolean

pad()

Makes the bounding sphere larger by the specified amount of padding.

Parameters

padding (float) – Distance to use as padding margin.

surface_area()

Returns the surface area of the bounding sphere.

Return type

float

union()

Union this bounding sphere instance with the input bounding sphere.

The resulting bounding sphere will be larger so as to just enclose both bounding spheres. This class instance will be edited in place to have the new bounding sphere dimensions.

Parameters

sphere (BoundingSphere3D) – A bounding sphere instance to union with this bounding sphere instance.

volume()

Returns the volume of the bounding sphere.

Return type

float