Skip to content

Commit 46177d2

Browse files
Jackyuanxu7678992TahitiXchopan050
authored
Fix wrong angle ranges in Sphere documentation and add more examples (#3973)
* Made the document changes * added additional example * Apply some suggestions from code review Co-authored-by: Francisco Manríquez Novoa <49853152+chopan050@users.noreply.github.com> * Shorten sphere examples * Fix line breaks and remove trailing whitespace * Add example for showing portions of spheres * Undo accidental overwrite of ExampleSphereOverlap * Change name of manim code block --------- Co-authored-by: Xiuyuan <u7678992@anu.edu.au> Co-authored-by: TahitiX <136950383+TahitiX@users.noreply.github.com> Co-authored-by: Francisco Manríquez Novoa <49853152+chopan050@users.noreply.github.com> Co-authored-by: Francisco Manríquez Novoa <francisco.manriquezn@usm.cl>
1 parent 4689298 commit 46177d2

1 file changed

Lines changed: 52 additions & 7 deletions

File tree

manim/mobject/three_d/three_dimensions.py

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -379,13 +379,7 @@ class Sphere(Surface):
379379
class ExampleSphere(ThreeDScene):
380380
def construct(self):
381381
self.set_camera_orientation(phi=PI / 6, theta=PI / 6)
382-
sphere1 = Sphere(
383-
center=(3, 0, 0),
384-
radius=1,
385-
resolution=(20, 20),
386-
u_range=[0.001, PI - 0.001],
387-
v_range=[0, TAU]
388-
)
382+
sphere1 = Sphere(center=(3, 0, 0), radius=1, resolution=(20, 20))
389383
sphere1.set_color(RED)
390384
self.add(sphere1)
391385
sphere2 = Sphere(center=(-1, -3, 0), radius=2, resolution=(18, 18))
@@ -394,6 +388,57 @@ def construct(self):
394388
sphere3 = Sphere(center=(-1, 2, 0), radius=2, resolution=(16, 16))
395389
sphere3.set_color(BLUE)
396390
self.add(sphere3)
391+
392+
This example shows that overlapping spheres can intersect with rough transitions.
393+
394+
.. manim:: ExampleSphereOverlap
395+
:save_last_frame:
396+
397+
class ExampleSphereOverlap(ThreeDScene):
398+
def construct(self):
399+
self.set_camera_orientation(phi=PI / 4, theta=PI / 4)
400+
sphere1 = Sphere(center=(0, 0, 0), radius=1, resolution=(20, 20))
401+
sphere1.set_color(RED)
402+
self.add(sphere1)
403+
sphere2 = Sphere(center=(-0.5, -1, 0.5), radius=1.2, resolution=(20, 20))
404+
sphere2.set_color(GREEN)
405+
self.add(sphere2)
406+
sphere3 = Sphere(center=(1, -1, 0), radius=1.1, resolution=(20, 20))
407+
sphere3.set_color(BLUE)
408+
self.add(sphere3)
409+
410+
In this example, by modifying ``u_range`` (the range of the azimuthal angle) and
411+
``v_range`` (the range of the polar angle), it is possible to obtain a portion of a
412+
sphere:
413+
414+
.. manim:: ExamplePartialSpheres
415+
:save_last_frame:
416+
417+
class ExamplePartialSpheres(ThreeDScene):
418+
def construct(self):
419+
self.set_camera_orientation(phi=PI / 4)
420+
sphere1 = Sphere(
421+
center=(-3, 0, 0),
422+
resolution=(10, 20),
423+
u_range=[TAU / 4, 3 * TAU / 4],
424+
)
425+
sphere1.set_color(RED)
426+
self.add(sphere1)
427+
sphere2 = Sphere(
428+
center=(0, 0, 0),
429+
resolution=(20, 10),
430+
v_range=[0, TAU / 4],
431+
)
432+
sphere2.set_color(GREEN)
433+
self.add(sphere2)
434+
sphere3 = Sphere(
435+
center=(3, 0, 0),
436+
resolution=(5, 10),
437+
u_range=[3 * TAU / 4, TAU],
438+
v_range=[TAU / 4, TAU / 2],
439+
)
440+
sphere3.set_color(BLUE)
441+
self.add(sphere3)
397442
"""
398443

399444
def __init__(

0 commit comments

Comments
 (0)