Skip to content

Commit 37fdd26

Browse files
committed
import SM base as smb
1 parent 69079d8 commit 37fdd26

File tree

2 files changed

+50
-50
lines changed

2 files changed

+50
-50
lines changed

spatialmath/base/graphics.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,10 @@ def plot_point(pos, marker="bs", text=None, ax=None, textargs=None, textcolor=No
142142
# [(x,y), (x,y), ...]
143143
# [xlist, ylist]
144144
# [xarray, yarray]
145-
if smbase.islistof(pos, (tuple, list)):
145+
if smb.islistof(pos, (tuple, list)):
146146
x = [z[0] for z in pos]
147147
y = [z[1] for z in pos]
148-
elif smbase.islistof(pos, np.ndarray):
148+
elif smb.islistof(pos, np.ndarray):
149149
x = pos[0]
150150
y = pos[1]
151151
else:
@@ -231,7 +231,7 @@ def plot_homline(lines, *args, ax=None, xlim=None, ylim=None, **kwargs):
231231

232232
# if lines.ndim == 1:
233233
# lines = lines.
234-
lines = smbase.getmatrix(lines, (3, None))
234+
lines = smb.getmatrix(lines, (3, None))
235235

236236
handles = []
237237
for line in lines.T: # for each column
@@ -323,7 +323,7 @@ def plot_box(
323323
"""
324324

325325
if wh is not None:
326-
if smbase.isscalar(wh):
326+
if smb.isscalar(wh):
327327
w, h = wh, wh
328328
else:
329329
w, h = wh
@@ -528,7 +528,7 @@ def plot_circle(
528528
>>> plot_circle(2, 'b--') # blue dashed circle
529529
>>> plot_circle(0.5, filled=True, facecolor='y') # yellow filled circle
530530
"""
531-
centres = smbase.getmatrix(centre, (2, None))
531+
centres = smb.getmatrix(centre, (2, None))
532532

533533
ax = axes_logic(ax, 2)
534534
handles = []
@@ -724,7 +724,7 @@ def plot_sphere(radius, centre=(0, 0, 0), pose=None, resolution=50, ax=None, **k
724724
"""
725725
ax = axes_logic(ax, 3)
726726

727-
centre = smbase.getmatrix(centre, (3, None))
727+
centre = smb.getmatrix(centre, (3, None))
728728

729729
handles = []
730730
for c in centre.T:
@@ -893,7 +893,7 @@ def plot_cylinder(
893893
894894
:seealso: :func:`~matplotlib.pyplot.plot_surface`, :func:`~matplotlib.pyplot.plot_wireframe`
895895
"""
896-
if smbase.isscalar(height):
896+
if smb.isscalar(height):
897897
height = [0, height]
898898

899899
ax = axes_logic(ax, 3)
@@ -1033,7 +1033,7 @@ def plot_cuboid(
10331033
vertices = vertices.T
10341034

10351035
if pose is not None:
1036-
vertices = smbase.homtrans(pose.A, vertices)
1036+
vertices = smb.homtrans(pose.A, vertices)
10371037

10381038
ax = axes_logic(ax, 3)
10391039
# plot sides
@@ -1315,7 +1315,7 @@ def expand_dims(dim=None, nd=2):
13151315
* [A,B] -> [A, B, A, B, A, B]
13161316
* [A,B,C,D,E,F] -> [A, B, C, D, E, F]
13171317
"""
1318-
dim = smbase.getvector(dim)
1318+
dim = smb.getvector(dim)
13191319

13201320
if nd == 2:
13211321
if len(dim) == 1:

spatialmath/base/transforms2d.py

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import math
1919
import numpy as np
2020
import scipy.linalg
21-
from spatialmath import base
21+
import spatialmath.base as smb
2222

2323
_eps = np.finfo(np.float64).eps
2424

@@ -52,9 +52,9 @@ def rot2(theta, unit="rad"):
5252
>>> rot2(0.3)
5353
>>> rot2(45, 'deg')
5454
"""
55-
theta = base.getunit(theta, unit)
56-
ct = base.sym.cos(theta)
57-
st = base.sym.sin(theta)
55+
theta = smb.getunit(theta, unit)
56+
ct = smb.sym.cos(theta)
57+
st = smb.sym.sin(theta)
5858
# fmt: off
5959
R = np.array([
6060
[ct, -st],
@@ -94,7 +94,7 @@ def trot2(theta, unit="rad", t=None):
9494
"""
9595
T = np.pad(rot2(theta, unit), (0, 1), mode="constant")
9696
if t is not None:
97-
T[:2, 2] = base.getvector(t, 2, "array")
97+
T[:2, 2] = smb.getvector(t, 2, "array")
9898
T[2, 2] = 1 # integer to be symbolic friendly
9999
return T
100100

@@ -121,7 +121,7 @@ def xyt2tr(xyt, unit="rad"):
121121
122122
:seealso: tr2xyt
123123
"""
124-
xyt = base.getvector(xyt, 3)
124+
xyt = smb.getvector(xyt, 3)
125125
T = np.pad(rot2(xyt[2], unit), (0, 1), mode="constant")
126126
T[:2, 2] = xyt[0:2]
127127
T[2, 2] = 1.0
@@ -211,13 +211,13 @@ def transl2(x, y=None):
211211
function.
212212
"""
213213

214-
if base.isscalar(x) and base.isscalar(y):
214+
if smb.isscalar(x) and smb.isscalar(y):
215215
# (x, y) -> SE(2)
216216
t = np.r_[x, y]
217-
elif base.isvector(x, 2):
217+
elif smb.isvector(x, 2):
218218
# R2 -> SE(2)
219-
t = base.getvector(x, 2)
220-
elif base.ismatrix(x, (3, 3)):
219+
t = smb.getvector(x, 2)
220+
elif smb.ismatrix(x, (3, 3)):
221221
# SE(2) -> R2
222222
return x[:2, 2]
223223
else:
@@ -264,7 +264,7 @@ def ishom2(T, check=False):
264264
and T.shape == (3, 3)
265265
and (
266266
not check
267-
or (base.isR(T[:2, :2]) and np.all(T[2, :] == np.array([0, 0, 1])))
267+
or (smb.isR(T[:2, :2]) and np.all(T[2, :] == np.array([0, 0, 1])))
268268
)
269269
)
270270

@@ -298,7 +298,7 @@ def isrot2(R, check=False):
298298
:seealso: isR, ishom2, isrot
299299
"""
300300
return (
301-
isinstance(R, np.ndarray) and R.shape == (2, 2) and (not check or base.isR(R))
301+
isinstance(R, np.ndarray) and R.shape == (2, 2) and (not check or smb.isR(R))
302302
)
303303

304304

@@ -466,55 +466,55 @@ def trexp2(S, theta=None, check=True):
466466
:seealso: trlog, trexp2
467467
"""
468468

469-
if base.ismatrix(S, (3, 3)) or base.isvector(S, 3):
469+
if smb.ismatrix(S, (3, 3)) or smb.isvector(S, 3):
470470
# se(2) case
471-
if base.ismatrix(S, (3, 3)):
471+
if smb.ismatrix(S, (3, 3)):
472472
# augmentented skew matrix
473-
if check and not base.isskewa(S):
473+
if check and not smb.isskewa(S):
474474
raise ValueError("argument must be a valid se(2) element")
475-
tw = base.vexa(S)
475+
tw = smb.vexa(S)
476476
else:
477477
# 3 vector
478-
tw = base.getvector(S)
478+
tw = smb.getvector(S)
479479

480-
if base.iszerovec(tw):
480+
if smb.iszerovec(tw):
481481
return np.eye(3)
482482

483483
if theta is None:
484-
(tw, theta) = base.unittwist2_norm(tw)
485-
elif not base.isunittwist2(tw):
484+
(tw, theta) = smb.unittwist2_norm(tw)
485+
elif not smb.isunittwist2(tw):
486486
raise ValueError("If theta is specified S must be a unit twist")
487487

488488
t = tw[0:2]
489489
w = tw[2]
490490

491-
R = base.rodrigues(w, theta)
491+
R = smb.rodrigues(w, theta)
492492

493-
skw = base.skew(w)
493+
skw = smb.skew(w)
494494
V = (
495495
np.eye(2) * theta
496496
+ (1.0 - math.cos(theta)) * skw
497497
+ (theta - math.sin(theta)) * skw @ skw
498498
)
499499

500-
return base.rt2tr(R, V @ t)
500+
return smb.rt2tr(R, V @ t)
501501

502-
elif base.ismatrix(S, (2, 2)) or base.isvector(S, 1):
502+
elif smb.ismatrix(S, (2, 2)) or smb.isvector(S, 1):
503503
# so(2) case
504-
if base.ismatrix(S, (2, 2)):
504+
if smb.ismatrix(S, (2, 2)):
505505
# skew symmetric matrix
506-
if check and not base.isskew(S):
506+
if check and not smb.isskew(S):
507507
raise ValueError("argument must be a valid so(2) element")
508-
w = base.vex(S)
508+
w = smb.vex(S)
509509
else:
510510
# 1 vector
511-
w = base.getvector(S)
511+
w = smb.getvector(S)
512512

513-
if theta is not None and not base.isunitvec(w):
513+
if theta is not None and not smb.isunitvec(w):
514514
raise ValueError("If theta is specified S must be a unit twist")
515515

516516
# do Rodrigues' formula for rotation
517-
return base.rodrigues(w, theta)
517+
return smb.rodrigues(w, theta)
518518
else:
519519
raise ValueError(" First argument must be SO(2), 1-vector, SE(2) or 3-vector")
520520

@@ -526,7 +526,7 @@ def adjoint2(T):
526526
return np.identity(2)
527527
elif T.shape == (3, 3):
528528
# SE(2) adjoint
529-
(R, t) = base.tr2rt(T)
529+
(R, t) = smb.tr2rt(T)
530530
# fmt: off
531531
return np.block([
532532
[R, np.c_[t[1], -t[0]].T],
@@ -567,7 +567,7 @@ def tr2jac2(T):
567567
raise ValueError("expecting an SE(2) matrix")
568568

569569
J = np.eye(3, dtype=T.dtype)
570-
J[:2, :2] = base.t2r(T)
570+
J[:2, :2] = smb.t2r(T)
571571
return J
572572

573573

@@ -608,10 +608,10 @@ def trinterp2(start, end, s=None):
608608
>>> trinterp2(None, T2, 1)
609609
>>> trinterp2(None, T2, 0.5)
610610
611-
:seealso: :func:`~spatialmath.base.transforms3d.trinterp`
611+
:seealso: :func:`~spatialmath.smb.transforms3d.trinterp`
612612
613613
"""
614-
if base.ismatrix(end, (2, 2)):
614+
if smb.ismatrix(end, (2, 2)):
615615
# SO(2) case
616616
if start is None:
617617
# TRINTERP2(T, s)
@@ -630,7 +630,7 @@ def trinterp2(start, end, s=None):
630630
th = th0 * (1 - s) + s * th1
631631

632632
return rot2(th)
633-
elif base.ismatrix(end, (3, 3)):
633+
elif smb.ismatrix(end, (3, 3)):
634634
if start is None:
635635
# TRINTERP2(T, s)
636636

@@ -653,7 +653,7 @@ def trinterp2(start, end, s=None):
653653
pr = p0 * (1 - s) + s * p1
654654
th = th0 * (1 - s) + s * th1
655655

656-
return base.rt2tr(rot2(th), pr)
656+
return smb.rt2tr(rot2(th), pr)
657657
else:
658658
return ValueError("Argument must be SO(2) or SE(2)")
659659

@@ -930,7 +930,7 @@ def _AlignSVD(source, reference):
930930
# translation is the difference between the point clound centroids
931931
t = ref_centroid - R @ src_centroid
932932

933-
return base.rt2tr(R, t)
933+
return smb.rt2tr(R, t)
934934

935935
def trplot2(
936936
T,
@@ -1035,11 +1035,11 @@ def trplot2(
10351035

10361036
# check input types
10371037
if isrot2(T, check=True):
1038-
T = base.r2t(T)
1038+
T = smb.r2t(T)
10391039
elif not ishom2(T, check=True):
10401040
raise ValueError("argument is not valid SE(2) matrix")
10411041

1042-
ax = base.axes_logic(ax, 2)
1042+
ax = smb.axes_logic(ax, 2)
10431043

10441044
try:
10451045
if not ax.get_xlabel():
@@ -1053,7 +1053,7 @@ def trplot2(
10531053
ax.set_aspect("equal")
10541054

10551055
if dims is not None:
1056-
ax.axis(base.expand_dims(dims))
1056+
ax.axis(smb.expand_dims(dims))
10571057
elif not hasattr(ax, "_plotvol"):
10581058
ax.autoscale(enable=True, axis="both")
10591059

@@ -1172,7 +1172,7 @@ def tranimate2(T, **kwargs):
11721172
tranimate2(transl(1,2)@trot2(1), frame='A', arrow=False, dims=[0, 5])
11731173
tranimate2(transl(1,2)@trot2(1), frame='A', arrow=False, dims=[0, 5], movie='spin.mp4')
11741174
"""
1175-
anim = base.animate.Animate2(**kwargs)
1175+
anim = smb.animate.Animate2(**kwargs)
11761176
try:
11771177
del kwargs["dims"]
11781178
except KeyError:

0 commit comments

Comments
 (0)