is_intersection_segment_aabb

compas_model.geometry.is_intersection_segment_aabb(segment, box)

Determine whether a segment intersects an axis aligned box.

Parameters:
segmentcompas.geometry.Line

The segment.

boxcompas.geometry.Box

The box.

Returns:
bool

True if the segmnet intersects the box. False otherwise.

Warning

The name of this function can be misleading, since it returns True not only when the segment intersects the box boundary, but also when the segment is contained inside the box.

This makes sense if you think of the box as a “solid”, but is less intuitive when you think of it as a “shell”.

Examples

Note that Line can be used as an infinite line, a rays, and as a segment between the two points at t=0 and t=1.

>>> from compas.geometry import Line
>>> from compas.geometry import Box
>>> from compas_model.geometry import is_intersection_segment_aabb

Create a box centered at the origin.

>>> box = Box(1, 1, 1)

A segment crossing the box boundary intersects the box.

>>> line = Line([0, 0, 0], [1, 0, 0])
>>> is_intersection_segment_aabb(line, box)
True

A segment contained inside the box interiro intersects the box.

>>> line = Line([0, 0, 0], [0.1, 0, 0])
>>> is_intersection_segment_aabb(line, box)
True

A segment outside the box but with one point on the box boundary intersects the box.

>>> line = Line([0.5, 0, 0], [1.5, 0, 0])
>>> is_intersection_segment_aabb(line, box)
True

A segment outside the box doesn’t intersect the box.

>>> line = Line([1.0, 0, 0], [2.0, 0, 0])
>>> is_intersection_segment_aabb(line, box)
False