Module Geometry¶

Shape¶ Shape class¶

Abstract class for CommonRoad shapes.

rotate_translate_local(translation, angle)[source]

First rotates a shape around the center and the translates it.

Return type: Shape
translate_rotate(translation, angle)[source]

First translates and then rotates a shape around the origin.

Return type: Shape

Rectangle class¶

class commonroad.geometry.shape.Rectangle(length, width, center=array([0., 0.]), orientation=0.0)[source]

The class Rectangle can be used to model occupied regions or rectangular obstacles, e.g., a vehicle. The rectangle is specified by the length in longitudinal direction, the width in lateral direction, the orientation, and its geometric center. If we model the shape of an obstacle, the orientation and geometric center can be omitted; therefore, we set the orientation, and the x- and y-coordinate of the geometric center to zero.

center

Geometric center of the rectangle [x, y]. If the rectangle is used to describe the shape of an obstacle, we set the center to the coordinates [0.0, 0.0].

Return type: ndarray
contains_point(point)[source]

Checks if a point is contained in a rectangle.

Parameters: point (ndarray) – 2D point as array [x, y] bool true if the rectangle’s interior or boundary intersects with the given point, otherwise false
length

Length of the rectangle in longitudinal direction.

Return type: float
orientation

Orientation of the rectangle. If the rectangle is used to describe the shape of an obstacle, we set the orientation to 0.0.

Return type: float
rotate_translate_local(translation, angle)[source]

A new rectangle is created by first rotating the rectangle around its center and then translating it.

Parameters: translation (ndarray) – translation vector [x_off, y_off] in x- and y-direction angle (float) – rotation angle in radian (counter-clockwise) Rectangle transformed rectangle
translate_rotate(translation, angle)[source]

A new rectangle is created by first translating and then rotating the rectangle around the origin.

Parameters: translation (ndarray) – translation vector [x_off, y_off] in x- and y-direction angle (float) – rotation angle in radian (counter-clockwise) Rectangle transformed rectangle
vertices

Vertices of the rectangle: [[x_0, y_0], [x_1, y_1], …].

Return type: ndarray
width

Width of the rectangle in lateral direction.

Return type: float

Circle class¶

The class Circle can be used to model occupied regions or circular obstacles, e.g., a pedestrian. A circle is defined by its radius and its geometric center. If we model the shape of an obstacle, the geometric center can be omitted and is set to [0.0, 0.0].

center

Geometric center [x, y] of the circle. If the circle is used to describe the shape of an obstacle, we set the center to the coordinates [0.0, 0.0].

Return type: ndarray
contains_point(point)[source]

Checks if a point is contained in a circle.

Parameters: point (ndarray) – 2D point [x, y] true if the circles’s interior or boundary intersects with the given point, otherwise false

The radius of the circle.

Return type: float
rotate_translate_local(translation, angle)[source]

A new circle is created by translating the center.

Parameters: translation (ndarray) – translation vector [x_off, y_off] in x- and y-direction angle (float) – rotation angle in radian (counter-clockwise) Circle transformed circle
translate_rotate(translation, angle)[source]

A new circle is created by first translating and then rotating the current circle around the origin.

Parameters: translation (ndarray) – translation vector [x_off, y_off] in x- and y-direction angle (float) – rotation angle in radian (counter-clockwise) Circle transformed circle

Polygon class¶

The class Polygon can be used to model occupied regions or obstacles. A polygon is defined by an array of ordered points (clockwise or counterclockwise).

center

Computes the geometric center of the polygon.

Return type: ndarray
contains_point(point)[source]

Checks if a point is contained in the polygon.

Parameters: point (ndarray) – 2D point bool true if the polygons’s interior or boundary intersects with the given point, otherwise false
rotate_translate_local(translation, angle)[source]

A new polygon is created by first rotating the polygon around its center and then translating it.

Parameters: translation (ndarray) – translation vector [x_off, y_off] in x- and y-direction angle (float) – rotation angle in radian (counter-clockwise) Polygon transformed polygon
translate_rotate(translation, angle)[source]

A new polygon is created by first translating and then rotating the current polygon.

Parameters: translation (ndarray) – translation vector [x_off, y_off] in x- and y-direction angle (float) – rotation angle in radian (counter-clockwise) Polygon transformed polygon
vertices

Array of ordered vertices of the polygon [[x_0, y_0], [x_1, y_1], …].

Return type: ndarray

ShapeGroup class¶

The class ShapeGroup represents a collection of primitive shapes, e.g., rectangles and polygons, which can be used to model occupied regions.

contains_point(point)[source]

Checks if a point is contained in any shape of the shape group.

Parameters: point () – 2D point [x, y] true if the interior or boundary of any shape intersects with the given point, otherwise false
rotate_translate_local(translation, angle)[source]

A new shape group is created by first rotating each shape around its center and then translating it.

Parameters: translation (ndarray) – translation vector [x_off, y_off] in x- and y-direction angle (float) – rotation angle in radian (counter-clockwise) ShapeGroup transformed shape group
shapes

Collection of shapes.

Return type: List[Shape]
translate_rotate(translation, angle)[source]

A new shape group is created by first translating and then rotating all shapes around the origin.

Parameters: translation (ndarray) – translation vector [x_off, y_off] in x- and y-direction angle (float) – rotation angle in radian (counter-clockwise) ShapeGroup transformed shape group

Transform¶

geometry.transform.translate_rotate(vertices, translation, angle)[source]

First translates the list of vertices, then rotates the list of vertices around the origin.

Parameters: vertices (ndarray) – array of 2D vertices [[x_0, y_0], [x_1, y_1], …] translation (Union[, List[float]]) – translation vector [x_off, y_off] in x- and y-direction angle (Union[float, int]) – rotation angle in radian (counter-clockwise) ndarray array of transformed vertices [[x’_0, y’_0], [x’_1, y’_1], …]
geometry.transform.rotate_translate(vertices, translation, angle)[source]

First rotates the list of vertices around the origin and then translates the list of vertices.

Parameters: vertices (ndarray) – array of 2D vertices [[x_0, y_0], [x_1, y_1], …] translation (Union[, List[float]]) – translation vector [x_off, y_off] in x- and y-direction angle (Union[float, int]) – rotation angle in radian (counter-clockwise) ndarray array of transformed vertices [[x’_0, y’_0], [x’_1, y’_1], …]
geometry.transform.rotation_translation_matrix(translation, angle)[source]

Creates a matrix that first rotates a vector around the origin and then translates it.

Parameters: translation (Union[, List[float]]) – offset in (x, y) for translating the vector angle (Union[float, int]) – angle in rad [-2pi, +2pi] ndarray matrix
geometry.transform.translation_rotation_matrix(translation, angle)[source]

Creates a matrix that first translates a homogeneous point, and then rotates it around the origin.

Parameters: translation (Union[, List[float]]) – offset in (x, y) for translating the vector angle (Union[float, int]) – angle in rad [-2pi, +2pi] ndarray matrix
geometry.transform.to_homogeneous_coordinates(points)[source]

Converts an array of vertices to homogeneous coordinates.

Parameters: points () – array of points ndarray homogeneous points
geometry.transform.from_homogeneous_coordinates(points)[source]

Converts an array of homogeneous vertices back to 2D.

Parameters: points – array of points ndarray array of 2D points