Module Geometry
Shape
Shape
class
- class commonroad.geometry.shape.Shape[source]
Abstract class for CommonRoad shapes.
- abstract contains_point(point)[source]
Checks whether point is contained in shape.
- Return type:
bool
Rectangle
class
- class commonroad.geometry.shape.Rectangle(length, width, center=None, 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.
- property center: ndarray
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].
- contains_point(point)[source]
Checks if a point is contained in a rectangle.
- Parameters:
point (
ndarray
) – 2D point as array [x, y]- Return type:
bool
- Returns:
true if the rectangle’s interior or boundary intersects with the given point, otherwise false
- draw(renderer, draw_params=None)[source]
Draw the object
- Parameters:
renderer (
IRenderer
) – Renderer to use for drawingdraw_params (
Union
[ShapeParams
,MPDrawParams
,None
]) – optional parameters for plotting, overriding the parameters of the renderer
- Returns:
None
- property length: float
Length of the rectangle in longitudinal direction.
- property orientation: float
Orientation of the rectangle. If the rectangle is used to describe the shape of an obstacle, we set the orientation to 0.0.
- 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-directionangle (
float
) – rotation angle in radian (counter-clockwise)
- Return type:
- Returns:
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-directionangle (
float
) – rotation angle in radian (counter-clockwise)
- Return type:
- Returns:
transformed rectangle
- property vertices: ndarray
Vertices of the rectangle: [[x_0, y_0], [x_1, y_1], …]. The vertices are sorted clockwise and the first and last point are the same.
- property width: float
Width of the rectangle in lateral direction.
Circle
class
- class commonroad.geometry.shape.Circle(radius, center=None)[source]
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].
- property center: ndarray
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].
- contains_point(point)[source]
Checks if a point is contained in a circle.
- Parameters:
point (
ndarray
) – 2D point [x, y]- Returns:
true if the circles’s interior or boundary intersects with the given point, otherwise false
- draw(renderer, draw_params=None)[source]
Draw the object
- Parameters:
renderer (
IRenderer
) – Renderer to use for drawingdraw_params (
Union
[ShapeParams
,MPDrawParams
,None
]) – optional parameters for plotting, overriding the parameters of the renderer
- Returns:
None
- property radius: float
The radius of the circle.
- 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-directionangle (
float
) – rotation angle in radian (counter-clockwise)
- Return type:
- Returns:
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-directionangle (
float
) – rotation angle in radian (counter-clockwise)
- Return type:
- Returns:
transformed circle
Polygon
class
- class commonroad.geometry.shape.Polygon(vertices)[source]
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).
- property center: ndarray
Computes the geometric center of the polygon.
- contains_point(point)[source]
Checks if a point is contained in the polygon.
- Parameters:
point (
ndarray
) – 2D point- Return type:
bool
- Returns:
true if the polygons’s interior or boundary intersects with the given point, otherwise false
- draw(renderer, draw_params=None)[source]
Draw the object
- Parameters:
renderer (
IRenderer
) – Renderer to use for drawingdraw_params (
Union
[ShapeParams
,MPDrawParams
,None
]) – optional parameters for plotting, overriding the parameters of the renderer
- Returns:
None
- 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-directionangle (
float
) – rotation angle in radian (counter-clockwise)
- Return type:
- Returns:
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-directionangle (
float
) – rotation angle in radian (counter-clockwise)
- Return type:
- Returns:
transformed polygon
- property vertices: ndarray
Vertices of the polygon [[x_0, y_0], [x_1, y_1], …]. The vertices are sorted clockwise and the first and last point are the same.
ShapeGroup
class
- class commonroad.geometry.shape.ShapeGroup(shapes)[source]
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 (
array
) – 2D point [x, y]- Returns:
true if the interior or boundary of any shape intersects with the given point, otherwise false
- draw(renderer, draw_params=None)[source]
Draw the object
- Parameters:
renderer (
IRenderer
) – Renderer to use for drawingdraw_params (
Union
[ShapeParams
,MPDrawParams
,None
]) – optional parameters for plotting, overriding the parameters of the renderer
- Returns:
None
- 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-directionangle (
float
) – rotation angle in radian (counter-clockwise)
- Return type:
- Returns:
transformed shape group
- 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-directionangle (
float
) – rotation angle in radian (counter-clockwise)
- Return type:
- Returns:
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
[array
,List
[float
]]) – translation vector [x_off, y_off] in x- and y-directionangle (
Union
[float
,int
]) – rotation angle in radian (counter-clockwise)
- Return type:
ndarray
- Returns:
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
[array
,List
[float
]]) – translation vector [x_off, y_off] in x- and y-directionangle (
Union
[float
,int
]) – rotation angle in radian (counter-clockwise)
- Return type:
ndarray
- Returns:
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
[array
,List
[float
]]) – offset in (x, y) for translating the vectorangle (
Union
[float
,int
]) – angle in rad [-2pi, +2pi]
- Return type:
ndarray
- Returns:
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
[array
,List
[float
]]) – offset in (x, y) for translating the vectorangle (
Union
[float
,int
]) – angle in rad [-2pi, +2pi]
- Return type:
ndarray
- Returns:
matrix
Polyline Utility Functions
- geometry.polyline_util.compute_polyline_lengths(polyline)[source]
Computes the path lengths of a given polyline in steps travelled from initial to final coordinate.
- Parameters:
polyline (
ndarray
) – Polyline with 2D points [[x_0, y_0], [x_1, y_1], …]- Return type:
ndarray
- Returns:
Path lengths of the polyline for each coordinate in m
- geometry.polyline_util.compute_total_polyline_length(polyline)[source]
Computes the complete path length of a given polyline.
- Parameters:
polyline (
ndarray
) – Polyline with 2D points [[x_0, y_0], [x_1, y_1], …]- Return type:
float
- Returns:
Path length of the polyline [m]
- geometry.polyline_util.compute_polyline_curvatures(polyline)[source]
Computes the curvatures along a given polyline travelled from initial to final coordinate.
- Parameters:
polyline (
ndarray
) – Polyline with 2D points [[x_0, y_0], [x_1, y_1], …]- Return type:
ndarray
- Returns:
Curvatures of the polyline for each coordinate [1/rad]
- geometry.polyline_util.compute_polyline_orientations(polyline)[source]
Computes the orientation of a given polyline travelled from initial to final coordinate. The orientation of the last coordinate is always assigned with the computed orientation of the penultimate one.
- Parameters:
polyline (
ndarray
) – Polyline with 2D points [[x_0, y_0], [x_1, y_1], …]- Return type:
ndarray
- Returns:
Orientations of the polyline for each coordinate [rad]
- geometry.polyline_util.compute_polyline_initial_orientation(polyline)[source]
Computes the orientation of the initial coordinate with respect to the succeeding coordinate.
- Parameters:
polyline (
ndarray
) – Polyline with 2D points [[x_0, y_0], [x_1, y_1], …]- Return type:
float
- Returns:
Orientation of the initial coordinate [rad]
- geometry.polyline_util.is_point_on_polyline(polyline, point)[source]
Computes whether a given point lies on a polyline. That means, the point is between the starting and ending point of the polyline.
- Parameters:
polyline (
ndarray
) – Polyline with 2D points [[x_0, y_0], [x_1, y_1], …]point (
ndarray
) – 2D point [x, y]
- Return type:
bool
- Returns:
Boolean indicating whether point lies on polyline or not
- geometry.polyline_util.compute_polyline_intersections(polyline_1, polyline_2)[source]
Computes the intersection points of two polylines.
- Parameters:
polyline_1 (
ndarray
) – First polyline with 2D points [[x_0, y_0], [x_1, y_1], …]polyline_2 (
ndarray
) – Second polyline with 2D points [[x_0, y_0], [x_1, y_1], …]
- Return type:
ndarray
- Returns:
Intersection points
- geometry.polyline_util.is_polyline_self_intersection(polyline)[source]
Computes whether the given polyline contains self-intersection. Intersection at boundary points are considered as self-intersection.
- Parameters:
polyline (
ndarray
) – Polyline with 2D points [[x_0, y_0], [x_1, y_1], …]- Return type:
bool
- Returns:
Self-intersection or not
- geometry.polyline_util.compare_polylines_equality(polyline_1, polyline_2, threshold=1e-10)[source]
Compares two polylines for equality. For equality of the values a threshold can be given.
- Parameters:
polyline_1 (
ndarray
) – First polyline with 2D points [[x_0, y_0], [x_1, y_1], …]polyline_2 (
ndarray
) – Second polyline with 2D points [[x_0, y_0], [x_1, y_1], …]threshold – Threshold for equality of values
- Return type:
bool
- Returns:
Equality of both polylines or not
- geometry.polyline_util.resample_polyline_with_number(polyline, number)[source]
Resamples the given polyline with a fixed number of points. The number of coordinates can be resampled down or up. There exists also an efficient C++ implementation with Python interface in the CommonRoad Drivability Checker.
- Parameters:
polyline (
ndarray
) – Polyline with 2D points [[x_0, y_0], [x_1, y_1], …]number (
int
) – Fixed number of 2D points
- Return type:
ndarray
- Returns:
Resampled polyline
- geometry.polyline_util.resample_polyline_with_distance(polyline, distance)[source]
Resamples the given polyline with a specific distance. For a higher distance than the length of the given polyline the polyline is not resampled. There exists also an efficient C++ implementation with Python interface in the CommonRoad Drivability Checker.
- Parameters:
polyline (
ndarray
) – Polyline with 2D points [[x_0, y_0], [x_1, y_1], …]distance (
float
) – Specific distance [m]
- Return type:
ndarray
- Returns:
Resampled polyline
- geometry.polyline_util.equalize_polyline_length(long_polyline, short_polyline)[source]
Inserts vertices into a polyline to be of the same length than other polyline.
- Parameters:
long_polyline (
ndarray
) – Polyline with higher number of verticesshort_polyline (
ndarray
) – Polyline with lower number of vertices
- Return type:
ndarray
- Returns:
Short polyline with equal length as long polyline
- geometry.polyline_util.create_indices_mapping(path_length_percentage_long, path_length_percentage_short)[source]
Extracts places (indices) where new vertices have to be added in shorter polyline. Helper function for insert_vertices
- Parameters:
path_length_percentage_long (
ndarray
) – Proportional path length along longer polylinepath_length_percentage_short (
ndarray
) – Proportional path length along shorter polyline
- Return type:
List
[int
]- Returns:
Mapping of existing indices of shorter polyline to longer polyline