8000 change point ordering to be compatible with MPL texture mapping · krishanrana/spatialmath-python@21a4846 · GitHub
[go: up one dir, main page]

Skip to content

Commit 21a4846

Browse files
committed
change point ordering to be compatible with MPL texture mapping
1 parent fcd39ec commit 21a4846

File tree

1 file changed

+9
-20
lines changed

1 file changed

+9
-20
lines changed

spatialmath/base/graphics.py

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,6 @@ def plot_ellipse(
584584

585585
# =========================== 3D shapes =================================== #
586586

587-
588587
def sphere(radius=1, centre=(0, 0, 0), resolution=50):
589588
"""
590589
Points on a sphere
@@ -600,12 +599,14 @@ def sphere(radius=1, centre=(0, 0, 0), resolution=50):
600599
601600
:seealso: :func:`plot_sphere`, :func:`~matplotlib.pyplot.plot_surface`, :func:`~matplotlib.pyplot.plot_wireframe`
602601
"""
603-
u = np.linspace(0.0, 2.0 * np.pi, resolution)
604-
v = np.linspace(0.0, np.pi, resolution)
602+
theta_range = np.linspace(0, np.pi, resolution)
603+
phi_range = np.linspace(-np.pi, np.pi, resolution)
604+
605+
Phi, Theta = np.meshgrid(phi_range, theta_range)
605606

606-
x = radius * np.outer(np.cos(u), np.sin(v)) + centre[0]
607-
y = radius * np.outer(np.sin(u), np.sin(v)) + centre[1]
608-
z = radius * np.outer(np.ones_like(u), np.cos(v)) + centre[2]
607+
x = radius * np.sin(Theta) * np.cos(Phi)
608+
y = radius * np.sin(Theta) * np.sin(Phi)
609+
z = radius * np.cos(Theta)
609610

610611
return (x, y, z)
611612

@@ -641,9 +642,8 @@ def plot_sphere(radius, centre=(0, 0, 0), pose=None, resolution=50, ax=None, **k
641642
.. runblock:: pycon
642643
643644
>>> from spatialmath.base import plot_sphere
644-
>>> plot_sphere(1, 'r') # red sphere wireframe
645-
>>> plot_sphere(1, centre=(1,1,1), filled=True, facecolor='b')
646-
645+
>>> plot_sphere(radius=1, color='r') # red sphere wireframe
646+
>>> plot_sphere(radius=1, centre=(1,1,1), filled=True, facecolor='b')
647647
648648
:seealso: :func:`~matplotlib.pyplot.plot_surface`, :func:`~matplotlib.pyplot.plot_wireframe`
649649
"""
@@ -654,17 +654,6 @@ def plot_sphere(radius, centre=(0, 0, 0), pose=None, resolution=50, ax=None, **k
654654
handles = []
655655
for c in centre.T:
656656
X, Y, Z = sphere(centre=c, radius=radius, resolution=resolution)
657-
658-
if pose is not None:
659-
xc = X.reshape((-1,))
660-
yc = Y.reshape((-1,))
661-
zc = Z.reshape((-1,))
662-
xyz = np.array((xc, yc, zc))
663-
xyz = pose * xyz
664-
X = xyz[0, :].reshape(x.shape)
665-
Y = xyz[1, :].reshape(y.shape)
666-
Z = xyz[2, :].reshape(z.shape)
667-
668657
handles.append(_render3D(ax, X, Y, Z, **kwargs))
669658

670659
return handles

0 commit comments

Comments
 (0)
0