summaryrefslogtreecommitdiffstats
path: root/manim
diff options
context:
space:
mode:
authorNao Pross <np@0hm.ch>2022-04-17 23:55:32 +0200
committerNao Pross <np@0hm.ch>2022-04-17 23:55:32 +0200
commit85d45cb2a89143fee1f4ac0e188c574b963645c1 (patch)
tree4d0857b49e23e664e05a4c2395fa4afc96099cc7 /manim
downloadFourierOnS2-85d45cb2a89143fee1f4ac0e188c574b963645c1.tar.gz
FourierOnS2-85d45cb2a89143fee1f4ac0e188c574b963645c1.zip
Add existing code
Diffstat (limited to 'manim')
-rw-r--r--manim/harmonics.py67
1 files changed, 67 insertions, 0 deletions
diff --git a/manim/harmonics.py b/manim/harmonics.py
new file mode 100644
index 0000000..a908e25
--- /dev/null
+++ b/manim/harmonics.py
@@ -0,0 +1,67 @@
+from manim import *
+from manim.mobject.opengl.opengl_surface import OpenGLSurface
+from manim.mobject.opengl.opengl_three_dimensions import OpenGLSurfaceMesh
+
+
+import numpy as np
+from scipy.special import sph_harm
+
+# configure style
+config.background_color = '#202020'
+config.tex_template.add_to_preamble(
+ r"\usepackage[p,osf]{scholax}"
+ r"\usepackage{amsmath}"
+ r"\usepackage[scaled=1.075,ncf,vvarbb]{newtxmath}"
+)
+
+class FourierOnS1(ThreeDScene):
+ @staticmethod
+ def harmonic_cos(m, n, theta, phi):
+ # get only the cos() part
+ r = np.real(sph_harm(m, n, theta, phi)) * 5 # Y_n^m
+
+ # coordinates transformation
+ x = r * np.cos(theta) * np.sin(phi)
+ y = r * np.sin(phi) * np.sin(theta)
+ z = r * np.cos(phi)
+
+ return [x, y, z]
+
+ @staticmethod
+ def harmonic_surf(m, n):
+ surf = Surface(lambda u, v: FourierOnS1.harmonic_cos(m, n, u, v),
+ u_range=[0, 2 * PI], v_range=[-PI, PI], resolution=[50, 50],
+ fill_opacity=.8, checkerboard_colors=[BLUE_D, BLUE_E])
+
+ return surf
+
+ def construct(self):
+ axes = ThreeDAxes(x_range=[-1, 1], y_range=[-1, 1])
+ self.add(axes)
+
+ self.set_camera_orientation(theta=30 * DEGREES, phi=75 * DEGREES)
+ self.begin_ambient_camera_rotation(rate=.1)
+
+ last_surf = None
+ last_label = None
+ for n in range(0, 5):
+ for m in range(0, n):
+ surf = FourierOnS1.harmonic_surf(m, n)
+ label = MathTex(r"Y_{%d}^{%d}(\theta, \phi)" % (n, m))
+
+ if last_surf is not None:
+ self.play(ReplacementTransform(last_surf, surf))
+
+ if last_label is not None:
+ self.remove(last_label)
+
+ self.play(Create(surf))
+ self.add_fixed_in_frame_mobjects(label)
+ label.to_corner(UL)
+
+ last_surf = surf
+ last_label = label
+
+ self.wait()
+
+ self.wait(5)