Skip to content

Commit b247635

Browse files
committed
refactor rt2tr to handle symbolics
1 parent d19f9fa commit b247635

1 file changed

Lines changed: 22 additions & 9 deletions

File tree

spatialmath/base/transformsNd.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -228,16 +228,29 @@ def rt2tr(R, t, check=False):
228228
if check and not isR(R):
229229
raise ValueError("Invalid rotation matrix")
230230

231-
if R.shape == (2, 2):
232-
T = np.eye(3)
233-
T[:2, :2] = R
234-
T[:2, 2] = t
235-
elif R.shape == (3, 3):
236-
T = np.eye(4)
237-
T[:3, :3] = R
238-
T[:3, 3] = t
231+
if R.dtype == "O":
232+
if R.shape == (2, 2):
233+
T = np.pad(R, ((0, 1), (0, 1)), 'constant')
234+
T[:2, 2] = t
235+
T[2, 2] = 1
236+
elif R.shape == (3, 3):
237+
T = np.pad(R, ((0, 1), (0, 1)), 'constant')
238+
T[:3, 3] = t
239+
T[3, 3] = 1
240+
else:
241+
raise ValueError("R must be an SO2 or SO3 rotation matrix")
239242
else:
240-
raise ValueError("R must be an SO2 or SO3 rotation matrix")
243+
244+
if R.shape == (2, 2):
245+
T = np.eye(3)
246+
T[:2, :2] = R
247+
T[:2, 2] = t
248+
elif R.shape == (3, 3):
249+
T = np.eye(4)
250+
T[:3, :3] = R
251+
T[:3, 3] = t
252+
else:
253+
raise ValueError("R must be an SO2 or SO3 rotation matrix")
241254

242255
return T
243256

0 commit comments

Comments
 (0)