# Python日报0411

manim 专栏收录该内容
1 篇文章 0 订阅

## 使用manim数学引擎复习python语言基本元素

from manimlib.imports import *

class Projectile(Scene):
def construct(self):
axes = Axes(
x_min = (-5) * (np.sqrt(5) - 1), x_max = 40,
y_min = (-5) * (np.sqrt(5) - 1), y_max = 25,
center_point = LEFT*3 + DOWN*2,
axis_config={
"unit_size": 0.2,
"tick_frequency": 5,
}
)

[-5]+[i for i in range(5, 45, 5)],
[-5]+[i for i in range(5, 25, 5)]
)
self.play(ShowCreation(axes))
unit_size = 0.2

t = ValueTracker(0)
v0 = 20                         # 初速度
theta = PI/3                    # 抛射角
height = 8                      # 抛射高
g = 9.8
args = [(-1)*0.5 * 9.8, v0 * np.sin(theta), height]
sov = np.roots(args)
np.array([
(v0 * np.cos(theta) * t.get_value()) * unit_size - 3,
(v0 * np.sin(theta) * t.get_value() - 0.5 * g * t.get_value() **2 + height ) * unit_size - 2,
0
])
))
apex_t = ((-1)*args[1]) /( 2 * args[0])
path = TracedPath(dot.get_center, stroke_width=4, stroke_color=WHITE)
label = VGroup(
TexMobject("y=", color=WHITE),
DecimalNumber(8, color=WHITE),
).arrange(RIGHT)\
v0 * np.sin(theta) * t.get_value() - 0.5 * g * t.get_value() ** 2 + height
))

self.play(Write(dot), Write(label))
t_1 = apex_t
self.play(t.set_value, t_1, run_time=t_1, rate_func=linear)

label_1 = label.copy().clear_updaters()
t = ValueTracker(t_1)
self.play(Write(label_1))
t_2 = sov[0]
self.play(t.set_value, t_2, run_time=t_2-t_1, rate_func=linear)

label_2 = VGroup(
TexMobject("x=", color=WHITE),
DecimalNumber(v0 * np.cos(theta) * t.get_value(), color=WHITE),
).arrange(RIGHT).next_to(dot, UP, buff=1)
self.play(Write(label_2))
t = ValueTracker(t_2)
self.play(t.set_value, 5, run_time=5-t_2, rate_func=linear)

self.wait(2)


Projectile

（修改常量初速度、抛射角、抛射高可以绘制任意抛体图像）

• 1
点赞
• 1
评论
• 0
收藏
• 一键三连
• 扫一扫，分享海报

01-31
04-09 1821
06-27 3101
08-19 137