8000 Plucker tidyup · flyinger/spatialmath-python@eaa3cd4 · GitHub
[go: up one dir, main page]

Skip to content

Commit eaa3cd4

Browse files
committed
Plucker tidyup
inherit from SMUserList fix repr, add pretty repr
1 parent c9190b4 commit eaa3cd4

File tree

1 file changed

+37
-11
lines changed

1 file changed

+37
-11
lines changed

spatialmath/geom3d.py

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010
import matplotlib.pyplot as plt
1111
from mpl_toolkits.mplot3d import Axes3D
1212
from spatialmath import SE3
13+
from spatialmath.smuserlist import SMUserList
1314

1415
_eps = np.finfo(np.float64).eps
1516

16-
17+
# ======================================================================== #
18+
1719
class Plane:
1820
r"""
1921
Create a plane object from linear coefficients
@@ -31,8 +33,8 @@ def __init__(self, c):
3133
self.plane = arg.getvector(c, 4)
3234

3335
# point and normal
34-
@staticmethod
35-
def PN(p, n):
36+
@classmethod
37+
def PN(cls, p, n):
3638
"""
3739
Create a plane object from point and normal
3840
@@ -46,11 +48,11 @@ def PN(p, n):
4648
"""
4749
n = arg.getvector(n, 3) # normal to the plane
4850
p = arg.getvector(p, 3) # point on the plane
49-
return Plane(np.r_[n, -np.dot(n, p)])
51+
return cls(np.r_[n, -np.dot(n, p)])
5052

5153
# point and normal
52-
@staticmethod
53-
def P3(p):
54+
@classmethod
55+
def P3(cls, p):
5456
"""
5557
Create a plane object from three points
5658
@@ -68,7 +70,7 @@ def P3(p):
6870
# compute a normal
6971
n = np.cross(v2-v1, v3-v1)
7072

71-
return Plane(n, v1)
73+
return cls(n, v1)
7274

7375
# line and point
7476
# 3 points
@@ -124,7 +126,9 @@ def __str__(self):
124126
"""
125127
return str(self.plane)
126128

127-
class Plucker(UserList):
129+
# ======================================================================== #
130+
131+
class Plucker(SMUserList):
128132
"""
129133
Plucker coordinate class
130134
@@ -239,6 +243,12 @@ def __init__(self, v=None, w=None):
239243
# needed to allow __rmul__ to work if left multiplied by ndarray
240244
#self.__array_priority__ = 100
241245

246+
def shape(self):
247+
return (6,)
248+
249+
@staticmethod
250+
def isvalid(x):
251+
return x.shape == self.shape
242252

243253
@staticmethod
244254
def PQ(P=None, Q=None):
@@ -993,13 +1003,29 @@ def __repr__(self):
9931003
"""
9941004

9951005
if len(self) == 1:
996-
return "Plucker([{:.5g}, {:.5g}, {:.5g}, {:.5g}, {:.5g}, {:.5g}])".format(*list(self))
1006+
return "Plucker([{:.5g}, {:.5g}, {:.5g}, {:.5g}, {:.5g}, {:.5g}])".format(*list(self.A))
9971007
else:
9981008
return "Plucker([\n" + \
999-
',\n'.join([" [{:.5g}, {:.5g}, {:.5g}, {:.5g}, {:.5g}, {:.5g}]".format(*list(tw)) for tw in self]) +\
1009+
',\n'.join([" [{:.5g}, {:.5g}, {:.5g}, {:.5g}, {:.5g}, {:.5g}]".format(*list(tw)) for tw in self.data]) +\
10001010
"\n])"
10011011

1002-
1012+
def _repr_pretty_(self, p, cycle):
1013+
"""
1014+
Pretty string for IPython (superclass method)
1015+
1016+
:param p: pretty printer handle (ignored)
1017+
:param cycle: pretty printer flag (ignored)
1018+
1019+
Print colorized output when variable is displayed in IPython, ie. on a line by
1020+
itself.
1021+
1022+
Example::
1023+
1024+
In [1]: x
1025+
1026+
"""
1027+
print(self.__str__())
1028+
10031029
# function z = side(self1, pl2)
10041030
# Plucker.side Plucker side operator
10051031
#

0 commit comments

Comments
 (0)
0