Skip to content

Commit 2858606

Browse files
committed
adds apply_tf_to_poses
1 parent 534f1dd commit 2858606

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

pose2d.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,26 @@ def apply_tf_to_pose(pose, pose2d):
5858
th = pose[2] + pose2d[2]
5959
return np.array([xy[0], xy[1], th])
6060

61+
def apply_tf_to_poses(poses, pose2d):
62+
"""
63+
Parameters
64+
----------
65+
poses: np.array
66+
Array of shape (N, 3), x, y, theta components of tfs of frame C in frame B)
67+
pose2d : np.array
68+
Array of shape (3,), x, y, theta components of the tf of frame B in frame A
69+
Returns
70+
-------
71+
result: np.array
72+
Array of shape (N, 3), x, y theta components of the tf of frame C in frame A
73+
"""
74+
result = np.zeros_like(poses)
75+
xy = rotate(poses[:, :2], pose2d[2]) + pose2d[:2][None, :]
76+
th = poses[:, 2] + pose2d[2]
77+
result[:, :2] = xy
78+
result[:, 2] = th
79+
return result
80+
6181
def apply_tf_to_vel(vel, pose2d):
6282
# same as apply_tf but assumes vel is xdot ydot thetadot instead of x y
6383
# for xdot ydot frame transformation applies,
@@ -78,7 +98,7 @@ def rotate(x, th):
7898
rotmat = np.array([
7999
[np.cos(th), -np.sin(th)],
80100
[np.sin(th), np.cos(th)],
81-
])
101+
])
82102
return np.matmul(rotmat, x.T).T
83103

84104
def inverse_pose2d(pose2d):

0 commit comments

Comments
 (0)