1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
from manimlib.imports import *
class Sphere(ThreeDScene):
def construct(self):
axes = ThreeDAxes() # creates a 3D Axis
text3d1 = TextMobject(r"$z = f(x,y) = \sqrt{r^2 - x^2 - y^2}$")
text3d1.scale(0.7)
text3d1.to_corner(UL)
text3d1.set_color_by_gradient(RED, ORANGE, YELLOW, GREEN, BLUE, PURPLE)
self.play(Write(text3d1))
self.wait(1)
self.add_fixed_in_frame_mobjects(text3d1)
sphere = ParametricSurface(
lambda u, v: np.array([
2*np.sin(u)*np.cos(v),
2*np.sin(u)*np.sin(v),
2*np.cos(u)
]),u_min=0,u_max=PI/2,v_min=0,v_max=2*PI,checkerboard_colors=[RED_D, RED_E],
resolution=(15, 32)).scale(1)
#Experiment with circles by changing difference value of u and v
'''
sphere_points = [np.array([2*np.sin(u*DEGREES)*np.cos(v*DEGREES), 2*np.sin(u*DEGREES)*np.sin(v*DEGREES), 2*np.cos(u*DEGREES)]) for u in range(0, 185, 5) for v in range(0, 365, 5)]
sphere_spheres = [Dot().move_to(pts) for pts in sphere_points]
sphere = VGroup(*sphere_spheres)
'''
self.set_camera_orientation(phi=75 * DEGREES, theta = 45*DEGREES)
self.add(axes)
axis = TextMobject(r"X",r"Y",r"Z")
axis[0].move_to(6*RIGHT)
axis[1].move_to(6*UP)
axis[2].move_to(np.array([0,0,3.7]))
self.add_fixed_orientation_mobjects(axis[2])
self.add_fixed_orientation_mobjects(axis[0])
self.add_fixed_orientation_mobjects(axis[1])
dot_x_y1 = Dot().scale(0.75).set_fill(RED_C).move_to(np.array([-1,1,0]))
dot_x_y_z1 = Dot().scale(0.75).set_fill(RED_C).move_to(np.array([-1,1,1.414]))
line1 = DashedLine(np.array([-1,1,0]), np.array([-1,1,1.414]), color = YELLOW_C)
point_x_y1 = TexMobject("(-1,1,0)").set_color(BLUE_C).move_to(np.array([-1.5,1.5,0])).scale(0.5)
point_x_y_z1 = TexMobject("(-1,1,\\sqrt{r^2 - x^2 - y^2})").set_color(BLUE_C).move_to(np.array([-1.5,1.5,1.414])).scale(0.5)
point_x_y_z1_2 = TexMobject("(-1,1,\\sqrt{4 - x^2 - y^2})").set_color(BLUE_C).move_to(np.array([-1.5,1.5,1.414])).scale(0.5)
point_x_y_z1_3 = TexMobject("(-1,1,\\sqrt{4 - 1 - 1})").set_color(BLUE_C).move_to(np.array([-1.5,1.5,1.414])).scale(0.5)
point_x_y_z1_4 = TexMobject("(-1,1,\\sqrt{2})").set_color(BLUE_C).move_to(np.array([-1.5,1.5,1.414])).scale(0.5)
point_x_y_z1_5 = TexMobject("(-1,1,1.414)").set_color(BLUE_C).move_to(np.array([-1.5,1.5,1.414])).scale(0.5)
self.play(ShowCreation(dot_x_y1))
self.add_fixed_orientation_mobjects(point_x_y1)
self.play(ShowCreation(dot_x_y_z1), ShowCreation(line1))
self.add_fixed_orientation_mobjects(point_x_y_z1)
self.wait(0.5)
self.play(ReplacementTransform(point_x_y_z1,point_x_y_z1_2))
self.add_fixed_orientation_mobjects(point_x_y_z1_2)
self.wait(0.5)
self.play(ReplacementTransform(point_x_y_z1_2,point_x_y_z1_3))
self.add_fixed_orientation_mobjects(point_x_y_z1_3)
self.wait(0.5)
self.play(ReplacementTransform(point_x_y_z1_3,point_x_y_z1_4))
self.add_fixed_orientation_mobjects(point_x_y_z1_4)
self.wait(0.5)
self.play(ReplacementTransform(point_x_y_z1_4,point_x_y_z1_5))
self.add_fixed_orientation_mobjects(point_x_y_z1_5)
dot_x_y2 = Dot().scale(0.75).set_fill(RED_C).move_to(np.array([0.5,-0.5,0]))
dot_x_y_z2 = Dot().scale(0.75).set_fill(RED_C).move_to(np.array([0.5,-0.5,1.87]))
line2 = DashedLine(np.array([0.5,-0.5,0]), np.array([0.5,-0.5,1.87]), color = YELLOW_C)
point_x_y2 = TexMobject("(0.5,-0.5,0)").set_color(BLUE_C).move_to(np.array([1.5,-1.5,0])).scale(0.5)
point_x_y_z2 = TexMobject("(0.5,-0.5,\\sqrt{r^2 - x^2 - y^2})").set_color(BLUE_C).move_to(np.array([1.5,-1.5,1.87])).scale(0.5)
point_x_y_z2_2 = TexMobject("(0.5,-0.5,\\sqrt{4 - x^2 - y^2})").set_color(BLUE_C).move_to(np.array([1.5,-1.5,1.87])).scale(0.5)
point_x_y_z2_3 = TexMobject("(0.5,-0.5,\\sqrt{4 - 0.25 - 0.25})").set_color(BLUE_C).move_to(np.array([1.5,-1.5,1.87])).scale(0.5)
point_x_y_z2_4 = TexMobject("(0.5,-0.5,\\sqrt{3.5})").set_color(BLUE_C).move_to(np.array([1.5,-1.5,1.87])).scale(0.5)
point_x_y_z2_5 = TexMobject("(0.5,-0.5,1.87)").set_color(BLUE_C).move_to(np.array([1.5,-1.5,1.87])).scale(0.5)
self.play(ShowCreation(dot_x_y2))
self.add_fixed_orientation_mobjects(point_x_y2)
self.play(ShowCreation(dot_x_y_z2), ShowCreation(line2))
self.add_fixed_orientation_mobjects(point_x_y_z2)
self.wait(0.5)
self.play(ReplacementTransform(point_x_y_z2,point_x_y_z2_2))
self.add_fixed_orientation_mobjects(point_x_y_z2_2)
self.wait(0.5)
self.play(ReplacementTransform(point_x_y_z2_2,point_x_y_z2_3))
self.add_fixed_orientation_mobjects(point_x_y_z2_3)
self.wait(0.5)
self.play(ReplacementTransform(point_x_y_z2_3,point_x_y_z2_4))
self.add_fixed_orientation_mobjects(point_x_y_z2_4)
self.wait(0.5)
self.play(ReplacementTransform(point_x_y_z2_4,point_x_y_z2_5))
self.add_fixed_orientation_mobjects(point_x_y_z2_5)
self.play(FadeOut(point_x_y1), FadeOut(point_x_y_z1_5))
self.play(FadeOut(point_x_y2), FadeOut(point_x_y_z2_5))
sphere_final = []
for u in range(0, 90, 15):
sphere_points1 = [np.array([2*np.sin(u*DEGREES)*np.cos(v*DEGREES), 2*np.sin(u*DEGREES)*np.sin(v*DEGREES), 2*np.cos(u*DEGREES)]) for v in range(0, 370, 10)]
sphere_dots1 = [Dot().scale(0.75).set_fill(RED_C).move_to(pts) for pts in sphere_points1]
sphere_points2 = [np.array([2*np.sin((u+5)*DEGREES)*np.cos(v*DEGREES), 2*np.sin((u+5)*DEGREES)*np.sin(v*DEGREES), 2*np.cos((u+5)*DEGREES)]) for v in range(0, 370, 10)]
sphere_dots2 = [Dot().scale(0.75).set_fill(RED_C).move_to(pts) for pts in sphere_points2]
sphere_points3 = [np.array([2*np.sin((u+10)*DEGREES)*np.cos(v*DEGREES), 2*np.sin((u+10)*DEGREES)*np.sin(v*DEGREES), 2*np.cos((u+10)*DEGREES)]) for v in range(0, 370, 10)]
sphere_dots3 = [Dot().scale(0.75).set_fill(RED_C).move_to(pts) for pts in sphere_points3]
sphere_final = sphere_final + sphere_dots1 + sphere_dots2 + sphere_dots3
sphere_dots = sphere_dots1 + sphere_dots2 + sphere_dots3
sphere_with_dots = VGroup(*sphere_dots)
self.play(ShowCreation(sphere_with_dots))
sphere_final_with_dots = VGroup(*sphere_final)
self.begin_ambient_camera_rotation(rate=0.5)
self.wait(3)
self.play(ReplacementTransform(sphere_final_with_dots, sphere))
self.wait(5)
|