File tree Expand file tree Collapse file tree 2 files changed +24
-5
lines changed Expand file tree Collapse file tree 2 files changed +24
-5
lines changed Original file line number Diff line number Diff line change 15
15
from scipy .linalg import logm , expm
16
16
17
17
from spatialmath .base .vectors import *
18
-
18
+ from spatialmath . base import sym
19
19
import matplotlib .pyplot as plt
20
20
21
21
@@ -74,8 +74,13 @@ def test_isunitvec(self):
74
74
self .assertFalse (isunitvec ([- 2 ]))
75
75
76
76
def test_norm (self ):
77
- nt .assert_array_almost_equal (norm ([0 , 0 , 0 ]), 0 )
78
- nt .assert_array_almost_equal (norm ([1 , 2 , 3 ]), math .sqrt (14 ))
77
+ self .assertAlmostEqual (norm ([0 , 0 , 0 ]), 0 )
78
+ self .assertAlmostEqual (norm ([1 , 2 , 3 ]), math .sqrt (14 ))
79
+
80
+ x , y = sym .symbol ('x y' )
81
+ v = [x , y ]
82
+ self .assertEqual (norm (v ), sym .sqrt (x ** 2 + y ** 2 ))
83
+ self .assertEqual (norm (np .r_ [v ]), sym .sqrt (x ** 2 + y ** 2 ))
79
84
80
85
def test_isunittwist (self ):
81
86
# 3D
Original file line number Diff line number Diff line change 15
15
import numpy as np
16
16
from spatialmath .base import getvector
17
17
18
+ try : # pragma: no cover
19
+ # print('Using SymPy')
20
+ from sympy import Matrix
21
+
22
+ _symbolics = True
23
+
24
+ except ImportError : # pragma: no cover
25
+ _symbolics = False
26
+
18
27
_eps = np .finfo (np .float64 ).eps
19
28
20
29
@@ -60,7 +69,7 @@ def unitvec(v):
60
69
"""
61
70
62
71
v = getvector (v )
63
- n = np . linalg . norm (v )
72
+ n = norm (v )
64
73
65
74
if n > 100 * _eps : # if greater than eps
66
75
return v / n
@@ -115,8 +124,13 @@ def norm(v):
115
124
116
125
:seealso: :func:`~spatialmath.base.unit`
117
126
127
+ :SymPy: supported
118
128
"""
119
- return np .linalg .norm (v )
129
+ v = getvector (v )
130
+ if v .dtype .kind == 'O' :
131
+ return Matrix (v ).norm ()
132
+ else :
133
+ return np .linalg .norm (v )
120
134
121
135
122
136
def isunitvec (v , tol = 10 ):
You can’t perform that action at this time.
0 commit comments