circulation.py
1from manim import *2import numpy as np3 4config.tex_template = TexTemplateLibrary.ctex5config.tex_template.add_to_preamble(r"\setCJKmainfont{STSong}")6 7class Circulation(ThreeDScene):8 def construct(self):9 # 创建标题10 title = Text("向量场的环流量", font="STSong", font_size=48)11 self.add_fixed_in_frame_mobjects(title)12 self.play(Write(title))13 self.wait(1)14 self.play(FadeOut(title))15 16 # 创建3D坐标系17 axes = ThreeDAxes(18 x_range=[-3, 3, 1],19 y_range=[-3, 3, 1],20 z_range=[-3, 3, 1],21 x_length=6,22 y_length=6,23 z_length=624 )25 26 # 设置相机视角27 self.set_camera_orientation(28 phi=70*DEGREES,29 theta=-45*DEGREES30 )31 32 self.play(Create(axes))33 self.wait(1)34 35 # 创建旋转向量场36 def vector_field_func(point):37 x, y, z = point38 return np.array([-y, x, 0]) / 239 40 # 创建向量场(蓝色箭头)- 减少向量数量41 vector_field = VGroup()42 for x in np.linspace(-2, 2, 5): # 减少为5x5的网格43 for y in np.linspace(-2, 2, 5):44 for z in [0]:45 point = np.array([x, y, z])46 vector = vector_field_func(point)47 arrow = Arrow3D(48 start=point,49 end=point + vector,50 color=BLUE,51 thickness=0.0252 )53 vector_field.add(arrow)54 55 # 添加向量场说明 - 添加向量符号56 field_label = MathTex(57 "\\vec{F}", 58 tex_template=TexTemplateLibrary.ctex,59 color=BLUE60 ).scale(1.2)61 field_label.shift(LEFT * 3.5) # 向中间平移62 63 self.add_fixed_in_frame_mobjects(field_label)64 self.play(Create(vector_field), Write(field_label))65 self.wait(1)66 67 # 创建圆形路径68 radius = 1.569 circle = Circle(radius=radius, color=YELLOW)70 circle.shift(OUT*0.01) # 稍微抬高以便看清71 72 # 创建路径箭头(表示路径方向)73 path_arrows = VGroup()74 n_arrows = 24 # 增加箭头数量75 for i in range(n_arrows):76 angle = i * TAU / n_arrows77 point = np.array([78 radius * np.cos(angle),79 radius * np.sin(angle),80 0.0181 ])82 next_angle = (i + 1) * TAU / n_arrows83 next_point = np.array([84 radius * np.cos(next_angle),85 radius * np.sin(next_angle),86 0.0187 ])88 arrow = Arrow3D(89 start=point,90 end=next_point,91 color=YELLOW,92 thickness=0.0293 )94 path_arrows.add(arrow)95 96 # 修改路径说明位置97 path_label = Text("闭合路径 C", font="STSong", font_size=30, color=YELLOW)98 path_label.shift(RIGHT * 3.5) # 向中间平移99 self.add_fixed_in_frame_mobjects(path_label)100 101 self.play(Create(circle), Create(path_arrows), Write(path_label))102 self.wait(1)103 104 # 创建移动的点和切向量105 dot = Sphere(radius=0.08, color=RED)106 dot.move_to(circle.point_from_proportion(0))107 108 # 创建切向量(显示做功)109 def get_work_vector(point):110 field_vector = vector_field_func(point)111 return Arrow3D(112 start=point,113 end=point + field_vector,114 color=GREEN,115 thickness=0.03116 )117 118 work_vector = get_work_vector(circle.point_from_proportion(0))119 120 # 添加做功说明121 work_label = Text("向量场沿路径做功", font="STSong", font_size=30, color=GREEN)122 work_label.next_to(path_label, DOWN)123 self.add_fixed_in_frame_mobjects(work_label)124 125 self.play(Create(dot), Create(work_vector), Write(work_label))126 self.wait(1)127 128 # 创建环流量公式129 circulation_formula = MathTex(130 "\\text{环流量} = \\oint_C \\vec{F} \\cdot d\\vec{r}",131 tex_template=TexTemplateLibrary.ctex132 ).scale(0.8)133 circulation_formula.to_corner(UR)134 135 explanation = Text(136 "环流量表示向量场沿闭合路径的总做功",137 font="STSong",138 font_size=24139 ).next_to(circulation_formula, DOWN+LEFT*0.5)140 141 self.add_fixed_in_frame_mobjects(circulation_formula, explanation)142 self.play(Write(circulation_formula), Write(explanation))143 self.wait(1)144 145 # 创建点的运动动画146 def update_dot_and_vector(mob, alpha):147 new_point = circle.point_from_proportion(alpha)148 dot.move_to(new_point)149 new_vector = get_work_vector(new_point)150 work_vector.become(new_vector)151 152 # 执行动画153 self.play(154 UpdateFromAlphaFunc(dot, update_dot_and_vector),155 run_time=8,156 rate_func=linear157 )158 self.wait(1)159 160 # 相机旋转161 self.begin_ambient_camera_rotation(rate=0.2)162 self.wait(4)163 self.stop_ambient_camera_rotation()164 self.wait(2)165 166def main():167 import os168 os.system("manim -pqh circulation.py Circulation")169 170if __name__ == "__main__":171 main() 讲解
这个视频围绕「向量场的环流量」展开。画面把问题、图像和公式放在同一条理解路径中,让抽象关系先被看见。
开头先建立问题背景和主要对象,让观察从标题、坐标或第一组关系进入。
画面中出现的文字「向量场的环流量」给出视觉入口。随后画面通过对象创建、移动、淡入淡出和高亮,把抽象命题拆成可以跟随的步骤。
随后出现更具体的图像或公式提示,动画会把局部对象和整体结论联系起来。这里可以重点观察变量、曲线、区域或向量如何随镜头推进而变化。
观察路径
观察路径可以分三步:先锁定「向量场的环流量」中的核心对象,尤其留意环流量、闭合环路积分、向量场之间的联系;再跟随画面中变量、图像或向量的变化;最后回到公式或结论,判断局部变化如何支撑整体关系。
本页可以从环流量、闭合环路积分、向量场、第二类曲线积分这些概念进入,继续沿相邻问题观察同一类数学结构。