BB.Collision.BroadPhase (bb v0.15.2)

Copy Markdown View Source

Broad phase collision detection using Axis-Aligned Bounding Boxes (AABBs).

The broad phase is a fast culling step that eliminates pairs of objects that cannot possibly be colliding. This reduces the number of expensive narrow-phase collision tests required.

AABBs are simple boxes aligned to the world axes, making overlap tests very fast. They may be larger than the actual geometry (especially for rotated objects), so a positive broad phase result only indicates potential collision.

Summary

Functions

Compute the centre point of an AABB.

Compute the AABB for a collision geometry in world space.

Check if a point is inside an AABB.

Expand an AABB by a margin in all directions.

Merge two AABBs into a single AABB that contains both.

Check if two AABBs overlap.

Compute the size (extents) of an AABB in each dimension.

Types

aabb()

@type aabb() :: {min :: BB.Math.Vec3.t(), max :: BB.Math.Vec3.t()}

Functions

centre(arg)

@spec centre(aabb()) :: BB.Math.Vec3.t()

Compute the centre point of an AABB.

compute_aabb(arg, transform)

@spec compute_aabb(BB.Robot.Link.geometry(), BB.Math.Transform.t()) :: aabb()

Compute the AABB for a collision geometry in world space.

Takes a geometry specification (as stored in Robot.Link) and a transform representing the geometry's position and orientation in world space.

Supported Geometry Types

  • {:sphere, %{radius: float()}} - Sphere
  • {:capsule, %{radius: float(), length: float()}} - Capsule (cylinder with spherical caps)
  • {:cylinder, %{radius: float(), height: float()}} - Cylinder (treated as capsule)
  • {:box, %{x: float(), y: float(), z: float()}} - Box

Examples

iex> geometry = {:sphere, %{radius: 1.0}}
iex> transform = Transform.identity()
iex> {min, max} = BB.Collision.BroadPhase.compute_aabb(geometry, transform)
iex> {Vec3.x(min), Vec3.x(max)}
{-1.0, 1.0}

contains_point?(arg, point)

@spec contains_point?(aabb(), BB.Math.Vec3.t()) :: boolean()

Check if a point is inside an AABB.

expand(arg, margin)

@spec expand(aabb(), float()) :: aabb()

Expand an AABB by a margin in all directions.

Useful for adding safety buffers to collision checks.

merge(arg1, arg2)

@spec merge(aabb(), aabb()) :: aabb()

Merge two AABBs into a single AABB that contains both.

overlap?(arg1, arg2)

@spec overlap?(aabb(), aabb()) :: boolean()

Check if two AABBs overlap.

This is a very fast O(1) test - two AABBs overlap if and only if they overlap on all three axes.

size(arg)

@spec size(aabb()) :: BB.Math.Vec3.t()

Compute the size (extents) of an AABB in each dimension.