Collision Detection

This module contains collision predicates and collision-space builders used by solvers and validators. It is one of the core geometric components in DiscoPygal.

Typical usage

from discopygal.geometry_utils.collision_detection import ObjectCollisionDetection

detector = ObjectCollisionDetection(obstacles, robot)
is_free = detector.is_point_valid(point)

See also

class discopygal.geometry_utils.collision_detection.ArrTraits(aos2: object, Arrangement_2: type, Curve_2: type, X_monotone_curve_2: type, TPoint: type, Face: type, point_location: type, overlay_traits: type)

The arrangement types of a single traits flavour. Segment traits are cheaper and are used whenever the scene consists of straight edges only; circle-segment traits are needed as soon as a circular arc appears (an expanded disc, or the boundary of an approximated offset). The two cannot be mixed inside one arrangement, nor overlaid with each other, so a single flavour is chosen per arrangement.

Arrangement_2: type

Alias for field number 1

Curve_2: type

Alias for field number 2

Face: type

Alias for field number 5

TPoint: type

Alias for field number 4

X_monotone_curve_2: type

Alias for field number 3

aos2: object

Alias for field number 0

overlay_traits: type

Alias for field number 7

point_location: type

Alias for field number 6

class discopygal.geometry_utils.collision_detection.ObjectCollisionDetection(obstaclces, robot, offset=0.05)

A class object that handles collision detection of a single object with obstacles. The collision detector builds a CGAL arrangement representing the scene and allows to (quickly) query the arrangement for collisions.

Parameters:
  • obstacles (list<Obstacle>) – list of obstacles

  • robot (Robot) – robot for building the collision detection

  • offset (FT) – offset for rod edge collision detection

build_cspace()

Build the Cspace arrangement

clean_redundant_halfedges(arr)

Given an arrangement, clear any halfedge that its both incident faces are nonfree.

Parameters:

arr (Arrangement_2) – arrangement to clean

expanded_obstacle_arrangement(obstacle)

Given a robot shape and the current obstacle, generate an arrangement that contains the (single) expanded obstacle

Parameters:

obstacle (Obstacle) – obstacle to expand

Returns:

arrangement with expanded obstacle

Return type:

Arrangement_2

is_edge_valid(edge) bool

Check if a edge (start point with angle to end point with angle) is valid (i.e. not colliding with anything).

Parameters:

edge (Segment_2) – edge to check

Returns:

False if edge intersects with the interior of an obstacle

Return type:

bool

is_edge_valid_rod(edge, clockwise) bool

Check if a edge is valid (i.e. not colliding with anything).

Parameters:
  • edge ((Segment_2, FT, FT)) – edge to check, as an 2D edge segment, and pair of angles start to end. The structure is: (segment, start_angle, end_angle)

  • clockwise (bool) – is the motion from start to end is clockwise or not

Returns:

False if edge intersects with the interior of an obstacle

Return type:

bool

is_point_valid(point) bool

Check if a point is valid (i.e. not colliding with anything).

Parameters:

point (Point_2) – point to check

Returns:

False if point lies in the interior of an obstacle

Return type:

bool

is_point_valid_rod(point) bool

Check if (rod) point and rotation are valid (i.e., not colliding with anything).

Parameters:

point – point to check: (point, angle)

Returns:

False if point lies in the interior of an obstacle

Return type:

bool

discopygal.geometry_utils.collision_detection.collide_disc_with_disc(center1, r1, center2, r2)

Collide (center ,r) disc with (center ,r) disc

Parameters:
  • center1 (Point_2) – center of the first disc to intersect

  • r1 (FT) – radius of first disc to intersect

  • center2 (Point_2) – center of the second disc to intersect

  • r2 (FT) – radius of second disc to intersect

Returns:

True if discs intersect

Return type:

bool

discopygal.geometry_utils.collision_detection.collide_disc_with_polygon(center, r, polygon)

Collide (center ,r) disc with CGAL polygon

Parameters:
  • center (Point_2) – center of the disc to intersect

  • r (FT) – radius of disc to intersect

  • polygon (Polygon_2) – polygon to intersect with

Returns:

True if disc and polygon intersect

Return type:

bool

discopygal.geometry_utils.collision_detection.collide_disc_with_rod(center, r, x, y, a, length) bool

Collide (center, r) disc with (x, y, a, length) rod

Parameters:
  • center (Ker.Point_2) – center of the disc to intersect

  • r (FT) – radius of disc to intersect

  • x (FT) – x of rod

  • y (FT) – y of rod

  • a (FT) – angle of rod

  • length (FT) – length of rod

Returns:

True if disc and segment intersect

Return type:

bool

discopygal.geometry_utils.collision_detection.collide_two_robots(robot1, edge1, robot2, edge2)

Get two robots and an edge of their movement, and check if at any point during their movement they intersect

Parameters:
  • robot1 (Robot) – first robot

  • edge1 (Segment_2) – first robot edge motion

  • robot2 (Robot) – second robot

  • edge2 (Segment_2) – second robot edge motion

Returns:

True if robots collide during motion

Return type:

bool

discopygal.geometry_utils.collision_detection.scene_traits(robot, obstacles) ArrTraits

Pick the arrangement traits needed to expand the given obstacles by the given robot.

A disc robot is offset by an approximated offset (arcs) against any obstacle, and a disc obstacle expands into arcs against any robot. Anything else stays polygonal.

Parameters:
  • robot (Robot) – robot the obstacles are expanded by

  • obstacles (list<Obstacle>) – obstacles of the scene

Returns:

the traits flavour to build the arrangement with

Return type:

ArrTraits