compas_model.geometry
¤
Functions¤
combine_aabbs
¤
combine_obbs
¤
intersection_ray_triangle
¤
Compute the intersection between a ray and a triangle.
Parameters:
Results
Point | 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 two identical points. 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 two identical points. 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 two identical points. 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 two identical points. If the number of intersections is 2 (two), the list contains two distinct points.
is_collision_poly_poly_xy
¤
Determine whether two convex polygons collide in the XY plane using the GJK algorithm.
Parameters:
Returns:
-
bool–True if the polygons collide. False otherwise.
Raises:
-
RuntimeError–If the GJK algorithm doesn't converge after 100 iterations.
Warnings
Only works for convex polygons in the XY plane.
Examples:
>>> from compas.geometry import Polygon
>>> from compas_model.geometry import is_collision_poly_poly_xy
Construct two polygons in the XY plane.
Check if the polygons collide.
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 :class: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.
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
¤
minkowski_difference_xy
¤
Compute the Minkowski difference of convex polygons A and B in the XY plane.
Parameters:
Returns:
-
Polygon–The polygon representing the difference as the sum of A and -B.
Warnings
Currently only convex polygons are supported.
See Also
Notes
The Minkwoski "difference" of two polygons A and B, can be formulated as the Minkowski sum of A and inverted B: A + (-B). 1
A useful application of the Minkowski difference of two convex polygons A and B is collision detection. If the origin (0, 0) is contained in the difference polygon A + (-B), then a collision between A and B exists.
-
https://en.wikipedia.org/wiki/Minkowski_addition ↩
Examples:
>>> from compas.geometry import Polygon
>>> from compas.geometry import is_point_in_convex_polygon_xy
>>> from compas_model.geometry import minkowski_difference_xy
minkowski_sum_xy
¤
Compute the Minkowski sum of two polygons.
Parameters:
Returns:
-
Polygon–The polygon representing the sum.
Warnings
Currently only convex polygons are supported.
See Also
pca_box
¤
Compute an oriented bounding box for the given points based on the principle components of the XYZ coordinates.
Parameters:
Returns:
-
Box–
Notes
The resulting box is not (necessarily) a minimum bounding volume. The box is computed by reprojecting the points onto the principle component vectors to identify the box extents. The origin of the box is found as the centroid of the points, corrected with the box extents.
Examples:
>>> import random
>>> import math
>>> from compas.geometry import Pointcloud
>>> from compas.geometry import Translation, Rotation
>>> from compas_model.geometry import pca_box
Construct a cloud of points.
Construct a random translation.
>>> vector = [10 * random.random(), 10 * random.random(), 10 * random.random()]
>>> T = Translation.from_vector(vector)
Construct a random rotation.
>>> axis = [random.random(), random.random(), random.random()]
>>> angle = math.radians(random.random() * 180)
>>> R = Rotation.from_axis_and_angle(axis, angle)
Transform the cloud and compute its PCA box.
Check.