8000 Add "flattening" from SE3 to SE2. · george0407/spatialmath-python@258a551 · GitHub
[go: up one dir, main page]

Skip to content

Commit 258a551

Browse files
committed
Add "flattening" from SE3 to SE2.
1 parent 0a7761d commit 258a551

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

spatialmath/pose3d.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -961,15 +961,7 @@ def __init__(self, x=None, y=None, z=None, *, check=True):
961961
elif isinstance(x, SO3):
962962
self.data = [smb.r2t(_x) for _x in x.data]
963963
elif isinstance(x, SE2): # type(x).__name__ == "SE2":
964-
965-
def convert(x):
966-
# convert SE(2) to SE(3)
967-
out = np.identity(4, dtype=x.dtype)
968-
out[:2, :2] = x[:2, :2]
969-
out[:2, 3] = x[:2, 2]
970-
return out
971-
972-
self.data = [convert(_x) for _x in x.data]
964+
self.data = x.SE3().data
973965
elif smb.isvector(x, 3):
974966
# SE3( [x, y, z] )
975967
self.data = [smb.transl(x)]
@@ -1170,6 +1162,9 @@ def inv(self) -> SE3:
11701162
else:
11711163
return SE3([smb.trinv(x) for x in self.A], check=False)
11721164

1165+
def SE2(self) -> SE2:
1166+
return SE2(self.x, self.y, self.rpy()[2])
1167+
11731168
def delta(self, X2: Optional[SE3] = None) -> R6:
11741169
r"""
11751170
Infinitesimal difference of SE(3) values

tests/test_pose3d.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,14 @@ def test_arith_vect(self):
659659
def test_functions(self):
660660
# inv
661661
# .T
662-
pass
662+
663+
# conversion to SE2
664+
poseSE3 = SE3.Tx(3.3) * SE3.Rz(1.5)
665+
poseSE2 = poseSE3.SE2()
666+
nt.assert_almost_equal(poseSE3.R[0:1,0:1], poseSE2.R[0:1,0:1])
667+
nt.assert_equal(poseSE3.x , poseSE2.x)
668+
nt.assert_equal(poseSE3.y , poseSE2.y)
669+
663670

664671
def test_functions_vect(self):
665672
# inv

0 commit comments

Comments
 (0)
0