【manim】3b1b的"Almost" Fourier Transform复刻
作者:互联网
最近在做Fourier Transform的内容,顺手记录一下一个下午的成果。
图像代码部分原理很简单,就是极坐标参数方程的转化。
原视频:https://www.youtube.com/watch?v=spUNpyF58BY&t=188s
bilibili:<iframe allowfullscreen="allowfullscreen" frameborder="no" height="277" scrolling="no" src="//player.bilibili.com/player.html?aid=19141078&bvid=BV1pW411J7s8&cid=31220967&page=1" style="width: 554px; height: 277px" width="554"> </iframe>
https://www.bilibili.com/video/BV1pW411J7s8?share_source=copy_web
数学公式在geogebra中构建如下:
manim代码:
from manim import *
class FourierTrans_First(Scene):
def construct(self):
axes = Axes(
x_range=[-0, 2*PI, PI/4],
y_range=[-0.1, 2.5, 1],
x_length=14,
y_length=2
).to_edge(UP)
axes_label = axes.get_axis_labels('Time','Intensity')
self.add(axes,axes_label)
polarPlane = PolarPlane(
radius_max=2.0,
#azimuth_units="PI radians",
azimuth_units="TAU radians",
size=4,
azimuth_label_font_size=24,
radius_config={"font_size": 24},
).add_coordinates().to_edge(DOWN+LEFT)
self.add(polarPlane)
#一些全局参数
delta = 0
rou = 1
move = 5
dn_kwargs = {
'show_ellipsis':False,
'num_decimal_places':3,
'include_sign':False,
#"unit": r"^\circ",
}
D_delta = DecimalNumber(delta,**dn_kwargs)
D_rou = DecimalNumber(rou,**dn_kwargs)
D_move = DecimalNumber(move,**dn_kwargs).shift(DOWN)
#解析式
raw = lambda t: np.sin(t) + 1
r = lambda t: np.sin(D_rou.get_value()*t+D_delta.get_value()) +1
par = lambda t: np.array([
r(t)*np.cos(D_move.get_value()*t),
r(t)*np.sin(D_move.get_value()*t),
0])
#更新函数
def Func_axes():
return axes.plot(r,color=ORANGE)
def Func_polar():
return polarPlane.plot_polar_graph(r, [0, 2 * PI], color=ORANGE)
def Func_para():
return ParametricFunction(
par
, t_range = np.array([0, 3.14*2])
, fill_opacity=0)\
.set_color(color=[RED,YELLOW,BLUE,RED])\
.to_edge(DOWN+RIGHT)
axes_graph = Func_axes()
polar_graph = Func_polar()
para_graph = Func_para()
axes_graph.add_updater(lambda mob: mob.become(Func_axes()))
polar_graph.add_updater(lambda mob: mob.become(Func_polar()))
para_graph.add_updater(lambda mob:mob.become(Func_para()))
self.add(D_rou,D_move)
self.play(Write(axes_graph),Write(polar_graph),Write(para_graph))
self.play(ChangeDecimalToValue(D_rou,15),run_time=10,rate_func=linear)
self.play(ChangeDecimalToValue(D_move,15),run_time=10,rate_func=linear)
self.wait(1)
标签:move,3b1b,Almost,graph,self,axes,add,Func,复刻 来源: https://www.cnblogs.com/remyuu/p/16471751.html