@@ -584,7 +584,6 @@ def plot_ellipse(
584
584
585
585
# =========================== 3D shapes =================================== #
586
586
587
-
588
587
def sphere (radius = 1 , centre = (0 , 0 , 0 ), resolution = 50 ):
589
588
"""
590
589
Points on a sphere
@@ -600,12 +599,14 @@ def sphere(radius=1, centre=(0, 0, 0), resolution=50):
600
599
601
600
:seealso: :func:`plot_sphere`, :func:`~matplotlib.pyplot.plot_surface`, :func:`~matplotlib.pyplot.plot_wireframe`
602
601
"""
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 )
605
606
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 )
609
610
610
611
return (x , y , z )
611
612
@@ -641,9 +642,8 @@ def plot_sphere(radius, centre=(0, 0, 0), pose=None, resolution=50, ax=None, **k
641
642
.. runblock:: pycon
642
643
643
644
>>> 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')
647
647
648
648
:seealso: :func:`~matplotlib.pyplot.plot_surface`, :func:`~matplotlib.pyplot.plot_wireframe`
649
649
"""
@@ -654,17 +654,6 @@ def plot_sphere(radius, centre=(0, 0, 0), pose=None, resolution=50, ax=None, **k
654
654
handles = []
655
655
for c in centre .T :
656
656
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
-
668
657
handles .append (_render3D (ax , X , Y , Z , ** kwargs ))
669
658
670
659
return handles
0 commit comments