torchdrivesim.utils¶
Miscellaneous utilities, including for geometric operations on tensors.
Classes¶
Functions¶
|
Checks whether elements of tensor x are contained in tensor y. |
|
Normalize to <-pi, pi) range by shifting by a multiple of 2*pi. |
|
Counterclockwise rotation matrix in 2D. |
|
Rotate the vector counterclockwise (from x towards y). |
|
Computes position and orientation of the target relative to origin. |
|
Given points relative to a pose, produce absolute positions of the points. |
|
Checks whether a given point is inside a given convex polygon. |
|
Merges a sequence of dictionaries, giving preference to entries earlier in the sequence. |
|
|
|
Determine intersections between batched line segments and circles in 2D. |
Module Contents¶
- torchdrivesim.utils.isin(x: torch.Tensor, y: torch.Tensor) torch.Tensor[source]¶
Checks whether elements of tensor x are contained in tensor y. This function is built-in in torch >= 1.10 and will be removed from here in the future.
- Parameters:
x – any tensor
y – a one-dimensional tensor
- Returns:
a boolean tensor with the same shape as x
- torchdrivesim.utils.normalize_angle(angle)[source]¶
Normalize to <-pi, pi) range by shifting by a multiple of 2*pi. Works with floats, numpy arrays, and torch tensors.
- torchdrivesim.utils.rotation_matrix(theta: torch.Tensor) torch.Tensor[source]¶
Counterclockwise rotation matrix in 2D.
- Parameters:
theta – tensor of shape Sx1 with rotation angle in radians
- Returns:
Sx2x2 tensor with the rotation matrix.
- torchdrivesim.utils.rotate(v: torch.Tensor, angle: torch.Tensor) torch.Tensor[source]¶
Rotate the vector counterclockwise (from x towards y). Works correctly in batch mode.
- Parameters:
v – tensor of shape Sx2 representing points
angle – tensor of shape Sx1 representing rotation angle
- Returns:
Sx2 tensor of rotated points
- torchdrivesim.utils.relative(origin_xy: torch.Tensor, origin_psi: torch.Tensor, target_xy: torch.Tensor, target_psi: torch.Tensor) Tuple[torch.Tensor, torch.Tensor][source]¶
Computes position and orientation of the target relative to origin. Points are represented as Sx2 tensors of coordinates and Sx1 tensors of orientations in radians.
- torchdrivesim.utils.transform(points: torch.Tensor, pose: torch.Tensor) torch.Tensor[source]¶
Given points relative to a pose, produce absolute positions of the points. There can be zero or more batch dimensions.
- Parameters:
points – BxNx2 tensor
pose – Bx3 tensor of position (x,y) and orientation (yaw angle in radians)
- Returns:
Bx2 tensor of absolute positions
- torchdrivesim.utils.is_inside_polygon(point: torch.Tensor, polygon: torch.Tensor) torch.Tensor[source]¶
Checks whether a given point is inside a given convex polygon. B and P can be zero or more batch dimensions, the former being batch and the latter points.
- Parameters:
point – BxPx2 tensor of x-y coordinates
polygon – BxNx2 tensor of points specifying a convex polygon in either clockwise or counter-clockwise fashion.
- Returns:
boolean tensor of shape BxP indicating whether the point is inside the polygon
- torchdrivesim.utils.merge_dicts(ds: List[Dict]) Dict[source]¶
Merges a sequence of dictionaries, giving preference to entries earlier in the sequence.
- torchdrivesim.utils.line_circle_intersection(p1: torch.Tensor, p2: torch.Tensor, circle_center: torch.Tensor, radius: torch.Tensor) torch.Tensor[source]¶
Determine intersections between batched line segments and circles in 2D.
- Parameters:
p1 (torch.Tensor) – Start points of line segments […, 2]
p2 (torch.Tensor) – End points of line segments […, 2]
circle_center (torch.Tensor) – Circle centers […, 2]
radius (torch.Tensor) – Circle radii […, 1]
- Returns:
Boolean tensor indicating intersections […, 1]
- Return type:
torch.Tensor