Skip to content

Commit 736b712

Browse files
committed
convert rotation matrix to 3-element analytical form as triple angles or expon coords
1 parent c73a8e1 commit 736b712

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

spatialmath/base/transforms3d.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1859,6 +1859,36 @@ def exp2jac(v):
18591859
)
18601860
return E
18611861

1862+
def tr2x(T, representation="rpy/xyz"):
1863+
t = transl(T)
1864+
R = base.t2r(T)
1865+
if representation == "rpy/xyz":
1866+
r = tr2rpy(R, order="xyz")
1867+
elif representation == "rpy/zyx":
1868+
r = tr2rpy(R, order="zyx")
1869+
elif representation == "eul":
1870+
r = tr2eul(R)
1871+
elif representation == "exp":
1872+
r = trlog(R, twist=True)
1873+
else:
1874+
raise ValueError(f"unknown representation: {representation}")
1875+
return np.r_[t, r]
1876+
1877+
def x2tr(x, representation="rpy/xyz"):
1878+
t = x[:3]
1879+
r = x[3:]
1880+
if representation == "rpy/xyz":
1881+
R = rpy2r(r, order="xyz")
1882+
elif representation == "rpy/zyx":
1883+
R = rpy2r(r, order="zyx")
1884+
elif representation == "eul":
1885+
R = eul2r(r)
1886+
elif representation == "exp":
1887+
R = trexp(r)
1888+
else:
1889+
raise ValueError(f"unknown representation: {representation}")
1890+
return base.rt2tr(R, t)
1891+
18621892

18631893
def rot2jac(R, representation="rpy-xyz"):
18641894
"""

0 commit comments

Comments
 (0)