10
10
import matplotlib .pyplot as plt
11
11
from mpl_toolkits .mplot3d import Axes3D
12
12
from spatialmath import SE3
13
+ from spatialmath .smuserlist import SMUserList
13
14
14
15
_eps = np .finfo (np .float64 ).eps
15
16
16
-
17
+ # ======================================================================== #
18
+
17
19
class Plane :
18
20
r"""
19
21
Create a plane object from linear coefficients
@@ -31,8 +33,8 @@ def __init__(self, c):
31
33
self .plane = arg .getvector (c , 4 )
32
34
33
35
# point and normal
34
- @staticmethod
35
- def PN (p , n ):
36
+ @classmethod
37
+ def PN (cls , p , n ):
36
38
"""
37
39
Create a plane object from point and normal
38
40
@@ -46,11 +48,11 @@ def PN(p, n):
46
48
"""
47
49
n = arg .getvector (n , 3 ) # normal to the plane
48
50
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 )])
50
52
51
53
# point and normal
52
- @staticmethod
53
- def P3 (p ):
54
+ @classmethod
55
+ def P3 (cls , p ):
54
56
"""
55
57
Create a plane object from three points
56
58
@@ -68,7 +70,7 @@ def P3(p):
68
70
# compute a normal
69
71
n = np .cross (v2 - v1 , v3 - v1 )
70
72
71
- return Plane (n , v1 )
73
+ return cls (n , v1 )
72
74
73
75
# line and point
74
76
# 3 points
@@ -124,7 +126,9 @@ def __str__(self):
124
126
"""
125
127
return str (self .plane )
126
128
127
- class Plucker (UserList ):
129
+ # ======================================================================== #
130
+
131
+ class Plucker (SMUserList ):
128
132
"""
129
133
Plucker coordinate class
130
134
@@ -239,6 +243,12 @@ def __init__(self, v=None, w=None):
239
243
# needed to allow __rmul__ to work if left multiplied by ndarray
240
244
#self.__array_priority__ = 100
241
245
246
+ def shape (self ):
247
+ return (6 ,)
248
+
249
+ @staticmethod
250
+ def isvalid (x ):
251
+ return x .shape == self .shape
242
252
243
253
@staticmethod
244
254
def PQ (P = None , Q = None ):
@@ -993,13 +1003,29 @@ def __repr__(self):
993
1003
"""
994
1004
995
1005
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 ))
997
1007
else :
998
1008
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 ]) + \
1000
1010
"\n ])"
1001
1011
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
+
1003
1029
# function z = side(self1, pl2)
1004
1030
# Plucker.side Plucker side operator
1005
1031
#
0 commit comments