Intersections¤
compas_model.geometry.intersections
¤
Functions:¤
intersection_ray_triangle
¤
Compute the intersection between a ray and a triangle.
Parameters:
Returns:
-
Point or None–The intersection point if one exists.
intersections_line_aabb
¤
Find the intersections between a line and an axis aligned box.
Parameters:
Returns:
-
tuple[bool, list[Point]]–The number of intersections, and a list of intersection points. If the number of intersections is 0 (zero), the list is empty. If the number of intersections is 1 (one), the list contains one point. If the number of intersections is 2 (two), the list contains two distinct points.
intersections_line_box
¤
Find the intersections between a line and a box.
Parameters:
Returns:
-
tuple[bool, list[Point]]–The number of intersections, and a list of intersection points. If the number of intersections is 0 (zero), the list is empty. If the number of intersections is 1 (one), the list contains one point. If the number of intersections is 2 (two), the list contains two distinct points.
intersections_ray_aabb
¤
Find the intersections between a ray and an axis aligned box.
Parameters:
Returns:
-
tuple[bool, list[Point]]–The number of intersections, and a list of intersection points. If the number of intersections is 0 (zero), the list is empty. If the number of intersections is 1 (one), the list contains one point. If the number of intersections is 2 (two), the list contains two distinct points.
intersections_ray_box
¤
Find the intersections between a ray and a box.
Parameters:
Returns:
-
tuple[bool, list[Point]]–The number of intersections, and a list of intersection points. If the number of intersections is 0 (zero), the list is empty. If the number of intersections is 1 (one), the list contains one point. If the number of intersections is 2 (two), the list contains two distinct points.
is_intersection_aabb_aabb
¤
is_intersection_aabb_aabb(
a: Box, b: Box, tolerance: float = 0.0, include_touching: bool = True
) -> bool
Determine whether two axis-aligned boxes intersect.
Parameters:
-
a(Box) –The first axis-aligned box.
-
b(Box) –The second axis-aligned box.
-
tolerance(float, default:0.0) –The maximum separation at which the boxes are still considered intersecting.
-
include_touching(bool, default:True) –If
True, boxes that only touch are considered intersecting.
Returns:
-
bool–Trueif the boxes intersect, andFalseotherwise.
Raises:
-
ValueError–If
toleranceis negative.
Notes
If touching is excluded, the boxes must overlap by more than tolerance
along every coordinate axis.
Examples:
>>> from compas.geometry import Box
>>> from compas.geometry import Translation
>>> from compas_model.geometry import is_intersection_aabb_aabb
>>> a = Box(1, 1, 1)
>>> b = Box(1, 1, 1)
>>> b.transform(Translation.from_vector([1, 0, 0]))
>>> is_intersection_aabb_aabb(a, b)
True
>>> is_intersection_aabb_aabb(a, b, include_touching=False)
False
is_intersection_box_box
¤
Determine whether a box intersects another box.
Parameters:
Returns:
-
bool–True if the boxes intersect. False otherwise.
Notes
The algorithm uses the method of separating axes, which states, for two convex objects: If there exists a line for which the intervals of projection of the two objects onto that line do not intersect, then the objects do not intersect.
The underlying theorem is described here 1.
For two oriented (bounding) boxes, this can be formulated in the form of 15 axis checks, based on the coordinate frames of the boxes, and the box coordinate extents.
-
https://en.wikipedia.org/wiki/Hyperplane_separation_theorem ↩
Examples:
>>> from compas.geometry import Box, Frame
>>> from compas_model.geometry import is_intersection_box_box
is_intersection_line_aabb
¤
is_intersection_line_box
¤
is_intersection_ray_aabb
¤
is_intersection_ray_box
¤
is_intersection_segment_aabb
¤
Determine whether a segment intersects an axis aligned box.
Parameters:
Returns:
-
bool–True if the segmnet intersects the box. False otherwise.
Warnings
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".
See Also
Examples:
Note that Line can be used as an infinite line, a ray, 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.
A segment crossing the box boundary intersects the box.
A segment contained inside the box interiro intersects the box.
A segment outside the box but with one point on the box boundary intersects the box.
A segment outside the box doesn't intersect the box.
is_intersection_segment_box
¤
is_intersection_sphere_aabb
¤
is_intersection_sphere_box
¤
is_line_contained_locally
¤
is_line_contained_locally(
point: Point | Vector, direction: Vector, dx: float, dy: float, dz: float
) -> bool
Determine whether the direction vector from a specific point is contained within the specified coordinate extents.
Parameters:
-
point(Point | Vector) –The base point of the direction.
-
direction(Vector) –The direction vector.
-
dx(float) –Extent of X coordinate.
-
dy(float) –Extent of Y coordinate.
-
dz(float) –Extent of Z coordinate.
Returns:
-
bool–True if the direction is contained. False otherwise.
is_ray_contained_locally
¤
Determine whether a ray is contained within the given extents along local axes.
Parameters:
-
point(Point | Vector) –The base point of the ray.
-
direction(Vector) –The direction of the ray.
-
extents(list[float]) –The coordinate extents along local axes.
Returns:
-
bool–True if the ray is contained. False otherwise.
is_segment_contained_locally
¤
is_segment_contained_locally(
point: Point | Vector,
direction: Vector,
box_extents: list[float],
segment_extent: float,
) -> bool
Determine whether a segment is contained within the given extents along local axes.
Parameters:
-
point(Point | Vector) –The midpoint of the segment.
-
direction(Vector) –The direction of the segment.
-
box_extents(list[float]) –The coordinate extents of the box along local axes.
-
segment_extent(float) –Coordinate extent of the segment along its direction, wrt its midpoint.
Returns:
-
bool–True if the segment is contained. False otherwise.