Rigid Body Transformations (transform.py)

The transform module provides 2D rigid body affine transformation utilities (translation, rotation, scaling) operating directly on CGAL geometric primitives (Point_2, Polygon_2, Segment_2).

Architectural Role

  • Robot Motion Simulation: Transforms robot geometry (polygons, discs, segments) from reference body frame coordinates to global world frame coordinates during planning and path validation.

  • Minkowski Sum Transformations: Inverts robot polygons around the origin for Minkowski difference calculations in ExactSingle.

  • Exact Arithmetic Transformations: Uses CGAL Aff_transformation_2 and Rotation matrices wrapped with exact field types (FT), preventing numerical drift.

Key Transformation Functions

  • translate_point(p, dx, dy): Translates a Point_2 by displacement vector (dx, dy).

  • translate_polygon(poly, dx, dy): Translates all vertices of a Polygon_2.

  • rotate_polygon(poly, angle, center): Rotates a polygon by angle radians around a center pivot point.

  • scale_polygon(poly, scale_x, scale_y): Applies non-uniform scaling to polygon vertices.

Usage Example

from discopygal.geometry_utils import transform
from discopygal.bindings import Point_2, FT

# Translate a polygon robot by (dx=3.0, dy=-1.5)
translated_poly = transform.translate_polygon(robot_poly, FT(3.0), FT(-1.5))

# Rotate around origin by 45 degrees (pi/4)
rotated_poly = transform.rotate_polygon(robot_poly, math.pi / 4)

API Reference

discopygal.geometry_utils.transform.offset_polygon(polygon: Any, offset: Any) Any

Offset a CGAL Polygon_2 with a given CGAL Point_2 x,y offset

Parameters:
Returns:

new offseted polygon

Return type:

Polygon_2