专栏文章
一分钟带你get凸透镜成像规律~(BV1ut8MzwE1j)
科技·工程参与者 1已保存评论 0
文章操作
快速查看文章及其快照的属性,并进行相关操作。
- 当前评论
- 0 条
- 当前快照
- 1 份
- 快照标识符
- @miorbaw7
- 此快照首次捕获于
- 2025/12/02 23:52 3 个月前
- 此快照最后确认于
- 2025/12/02 23:52 3 个月前
源代码:
PYTHONfrom manim import *
import math
import numpy as np
from scipy.optimize import fsolve
class Project(Scene):
def construct(self):
self.wait(1)
xOy = NumberPlane(
axis_config={
"stroke_color": BLUE
}
)
self.play(Write(xOy)) # 坐标纸
self.wait(1)
mirrowup = Arrow(
start=xOy.c2p(0, 0),
end=xOy.c2p(0, 3),
color=WHITE,
buff=0
)
mirrowdown = Arrow(
start=xOy.c2p(0, 0),
end=xOy.c2p(0, -3),
color=WHITE,
buff=0
)
self.play(FadeIn(mirrowup),FadeIn(mirrowdown)) # 凸透镜
self.wait(1)
custom_dotted_line = self.create_custom_dashed_line(
start=LEFT * 7.35,
end=RIGHT * 7.35,
dash_length=0.2,
dot_distance=0.3,
color=YELLOW,
stroke_width=3
)
self.play(FadeIn(custom_dotted_line)) # 主光轴
self.wait(1)
text1 = Text("F", font = "Consolas", font_size=36).move_to([-2, -0.25, 0])
text2 = Text("F", font = "Consolas", font_size=36).move_to([2, 0.25, 0])
text3 = Text("2F", font = "Consolas", font_size=36).move_to([-4, -0.25, 0])
text4 = Text("2F", font = "Consolas", font_size=36).move_to([4, 0.25, 0])
self.play(FadeIn(text1),FadeIn(text2),FadeIn(text3),FadeIn(text4)) # 焦距
self.wait(1)
# >2F
obj = Arrow(
start=xOy.c2p(-6, 0),
end=xOy.c2p(-6, 2),
color=RED,
buff=0
)
self.play(FadeIn(obj))
self.wait(1)
line1 = Line(
start=xOy.c2p(-6, 2),
end=xOy.c2p(0, 0),
stroke_width=3,
color=GRAY
)
light1 = Arrow(
start=xOy.c2p(-6, 2),
end=xOy.c2p(-3, 1),
stroke_width=3,
color=GRAY,
buff=0
)
line2 = Line(
start=xOy.c2p(-6, 2),
end=xOy.c2p(0, 2),
stroke_width=3,
color=GRAY
)
light2 = Arrow(
start=xOy.c2p(-6, 2),
end=xOy.c2p(-3, 2),
stroke_width=3,
color=GRAY,
buff=0
)
line3 = Line(
start=xOy.c2p(0, 0),
end=xOy.c2p(3, -1),
stroke_width=3,
color=GRAY
)
light3 = Arrow(
start=xOy.c2p(0, 0),
end=xOy.c2p(1.5, -0.5),
stroke_width=3,
color=GRAY,
buff=0
)
line4 = Line(
start=xOy.c2p(0, 2),
end=xOy.c2p(3, -1),
stroke_width=3,
color=GRAY
)
light4 = Arrow(
start=xOy.c2p(0, 2),
end=xOy.c2p(1.5, 0.5),
stroke_width=3,
color=GRAY,
buff=0
)
self.play(Create(line1), GrowArrow(light1), Create(line2), GrowArrow(light2))
self.wait(0.5)
self.play(Create(line3), GrowArrow(light3), Create(line4), GrowArrow(light4))
self.wait(1)
pic = Arrow(
start=xOy.c2p(3, 0),
end=xOy.c2p(3, -1),
color=RED,
buff=0
)
self.play(FadeIn(pic))
self.wait(3)
self.play(
FadeOut(line1),
FadeOut(light1),
FadeOut(line2),
FadeOut(light2),
FadeOut(line3),
FadeOut(light3),
FadeOut(line4),
FadeOut(light4),
FadeOut(pic),
)
self.wait(1)
# 2F
self.play(obj.animate.move_to(xOy.c2p(-4, 1)))
self.wait(1)
line1 = Line(
start=xOy.c2p(-4, 2),
end=xOy.c2p(0, 0),
stroke_width=3,
color=GRAY
)
light1 = Arrow(
start=xOy.c2p(-4, 2),
end=xOy.c2p(-2, 1),
stroke_width=3,
color=GRAY,
buff=0
)
line2 = Line(
start=xOy.c2p(-4, 2),
end=xOy.c2p(0, 2),
stroke_width=3,
color=GRAY
)
light2 = Arrow(
start=xOy.c2p(-4, 2),
end=xOy.c2p(-2, 2),
stroke_width=3,
color=GRAY,
buff=0
)
line3 = Line(
start=xOy.c2p(0, 0),
end=xOy.c2p(4, -2),
stroke_width=3,
color=GRAY
)
light3 = Arrow(
start=xOy.c2p(0, 0),
end=xOy.c2p(2, -1),
stroke_width=3,
color=GRAY,
buff=0
)
line4 = Line(
start=xOy.c2p(0, 2),
end=xOy.c2p(4, -2),
stroke_width=3,
color=GRAY
)
light4 = Arrow(
start=xOy.c2p(0, 2),
end=xOy.c2p(2, 0),
stroke_width=3,
color=GRAY,
buff=0
)
self.play(Create(line1), GrowArrow(light1), Create(line2), GrowArrow(light2))
self.wait(0.5)
self.play(Create(line3), GrowArrow(light3), Create(line4), GrowArrow(light4))
self.wait(1)
pic = Arrow(
start=xOy.c2p(4, 0),
end=xOy.c2p(4, -2),
color=RED,
buff=0
)
self.play(FadeIn(pic))
self.wait(3)
self.play(
FadeOut(line1),
FadeOut(light1),
FadeOut(line2),
FadeOut(light2),
FadeOut(line3),
FadeOut(light3),
FadeOut(line4),
FadeOut(light4),
FadeOut(pic),
)
# <2F >F
self.play(obj.animate.move_to(xOy.c2p(-3, 1)))
self.wait(1)
line1 = Line(
start=xOy.c2p(-3, 2),
end=xOy.c2p(0, 0),
stroke_width=3,
color=GRAY
)
light1 = Arrow(
start=xOy.c2p(-3, 2),
end=xOy.c2p(-1.5, 1),
stroke_width=3,
color=GRAY,
buff=0
)
line2 = Line(
start=xOy.c2p(-3, 2),
end=xOy.c2p(0, 2),
stroke_width=3,
color=GRAY
)
light2 = Arrow(
start=xOy.c2p(-3, 2),
end=xOy.c2p(-1.5, 2),
stroke_width=3,
color=GRAY,
buff=0
)
line3 = Line(
start=xOy.c2p(0, 0),
end=xOy.c2p(6, -4),
stroke_width=3,
color=GRAY
)
light3 = Arrow(
start=xOy.c2p(0, 0),
end=xOy.c2p(3, -2),
stroke_width=3,
color=GRAY,
buff=0
)
line4 = Line(
start=xOy.c2p(0, 2),
end=xOy.c2p(6, -4),
stroke_width=3,
color=GRAY
)
light4 = Arrow(
start=xOy.c2p(0, 2),
end=xOy.c2p(3, -1),
stroke_width=3,
color=GRAY,
buff=0
)
self.play(Create(line1), GrowArrow(light1), Create(line2), GrowArrow(light2))
self.wait(0.5)
self.play(Create(line3), GrowArrow(light3), Create(line4), GrowArrow(light4))
self.wait(1)
pic = Arrow(
start=xOy.c2p(6, 0),
end=xOy.c2p(6, -4),
color=RED,
buff=0
)
self.play(FadeIn(pic))
self.wait(3)
self.play(
FadeOut(line1),
FadeOut(light1),
FadeOut(line2),
FadeOut(light2),
FadeOut(line3),
FadeOut(light3),
FadeOut(line4),
FadeOut(light4),
FadeOut(pic),
)
# F
self.play(obj.animate.move_to(xOy.c2p(-2, 1)))
self.wait(1)
line1 = Line(
start=xOy.c2p(-2, 2),
end=xOy.c2p(0, 0),
stroke_width=3,
color=GRAY
)
light1 = Arrow(
start=xOy.c2p(-2, 2),
end=xOy.c2p(-1, 1),
stroke_width=3,
color=GRAY,
buff=0
)
line2 = Line(
start=xOy.c2p(-2, 2),
end=xOy.c2p(0, 2),
stroke_width=3,
color=GRAY
)
light2 = Arrow(
start=xOy.c2p(-2, 2),
end=xOy.c2p(-1, 2),
stroke_width=3,
color=GRAY,
buff=0
)
line3 = Line(
start=xOy.c2p(0, 0),
end=xOy.c2p(4, -4),
stroke_width=3,
color=GRAY
)
light3 = Arrow(
start=xOy.c2p(0, 0),
end=xOy.c2p(2, -2),
stroke_width=3,
color=GRAY,
buff=0
)
line4 = Line(
start=xOy.c2p(0, 2),
end=xOy.c2p(6, -4),
stroke_width=3,
color=GRAY
)
light4 = Arrow(
start=xOy.c2p(0, 2),
end=xOy.c2p(3, -1),
stroke_width=3,
color=GRAY,
buff=0
)
self.play(Create(line1), GrowArrow(light1), Create(line2), GrowArrow(light2))
self.wait(0.5)
self.play(Create(line3), GrowArrow(light3), Create(line4), GrowArrow(light4))
self.wait(3)
self.play(
FadeOut(line1),
FadeOut(light1),
FadeOut(line2),
FadeOut(light2),
FadeOut(line3),
FadeOut(light3),
FadeOut(line4),
FadeOut(light4),
)
# <F
self.play(obj.animate.move_to(xOy.c2p(-1, 1)))
self.wait(1)
line1 = Line(
start=xOy.c2p(-1, 2),
end=xOy.c2p(0, 0),
stroke_width=3,
color=GRAY
)
light1 = Arrow(
start=xOy.c2p(-1, 2),
end=xOy.c2p(-0.5, 1),
stroke_width=3,
color=GRAY,
buff=0
)
line2 = Line(
start=xOy.c2p(-1, 2),
end=xOy.c2p(0, 2),
stroke_width=3,
color=GRAY
)
light2 = Arrow(
start=xOy.c2p(-1, 2),
end=xOy.c2p(-0.5, 2),
stroke_width=3,
color=GRAY,
buff=0
)
line3 = Line(
start=xOy.c2p(0, 0),
end=xOy.c2p(2, -4),
stroke_width=3,
color=GRAY
)
light3 = Arrow(
start=xOy.c2p(0, 0),
end=xOy.c2p(1, -2),
stroke_width=3,
color=GRAY,
buff=0
)
line4 = Line(
start=xOy.c2p(0, 2),
end=xOy.c2p(6, -4),
stroke_width=3,
color=GRAY
)
light4 = Arrow(
start=xOy.c2p(0, 2),
end=xOy.c2p(3, -1),
stroke_width=3,
color=GRAY,
buff=0,
)
self.play(Create(line1), GrowArrow(light1), Create(line2), GrowArrow(light2))
self.wait(0.5)
self.play(Create(line3), GrowArrow(light3), Create(line4), GrowArrow(light4))
self.wait(1)
f3 = DashedVMobject(
Line(
start=xOy.c2p(-1, 2),
end=xOy.c2p(-2, 4),
color=GRAY
),
num_dashes=10,
dashed_ratio=0.5
)
f4 = DashedVMobject(
Line(
start=xOy.c2p(0, 2),
end=xOy.c2p(-2, 4),
color=GRAY
),
num_dashes=10,
dashed_ratio=0.5
)
self.play(Create(f3), Create(f4))
pic = DashedVMobject(
Arrow(
start=xOy.c2p(-2, 0),
end=xOy.c2p(-2, 4),
color=RED,
buff=0
),
num_dashes=10,
dashed_ratio=0.5
)
self.play(FadeIn(pic))
self.wait(3)
self.play(
FadeOut(line1),
FadeOut(light1),
FadeOut(line2),
FadeOut(light2),
FadeOut(line3),
FadeOut(light3),
FadeOut(line4),
FadeOut(light4),
FadeOut(pic),
FadeOut(f3),
FadeOut(f4),
FadeOut(xOy),
FadeOut(custom_dotted_line),
FadeOut(mirrowup),
FadeOut(mirrowdown),
FadeOut(text1),
FadeOut(text2),
FadeOut(text3),
FadeOut(text4),
FadeOut(obj)
)
self.wait(1)
text = Text("谢谢观看", color=WHITE)
self.play(FadeIn(text))
self.wait(2)
self.play(FadeOut(text))
self.wait(1)
def create_custom_dashed_line(self, start, end, dash_length, dot_distance, color, stroke_width):
direction = (end - start)
length = np.linalg.norm(direction)
unit_vector = direction / length if length > 0 else direction
total_segments = int((length) // (dash_length + dot_distance))
vgroup = VGroup()
current_point = start.copy()
for _ in range(total_segments):
dash_end = current_point + unit_vector * dash_length
dash = Line(current_point, dash_end, color=color, stroke_width=stroke_width)
vgroup.add(dash)
current_point = dash_end
dot_point = current_point + unit_vector * (dot_distance / 2)
dot = Dot(point=dot_point, radius=0.04, color=color)
vgroup.add(dot)
current_point = dot_point + unit_vector * (dot_distance / 2)
return vgroup
相关推荐
评论
共 0 条评论,欢迎与作者交流。
正在加载评论...