废话不多说,直接上干货。
在manim中所有可见的数学对象 都继承自 Mobject.
一般来说,点 组成了 线, 线组成了面。所以在继承上来说,应该是点 -> 线 -> 面。但是一般来讲的话,图像中表现出来的点一般都是一个小圆点。所以在manim中点 是 特殊的 圆。
那由简入难,一开始学习 线 是个不错的选择。manim中,包含了这么几个和线相关的类。
继承关系如下:
-
Line 普通的线
- DashedLine 虚线
- TangentLine 切线
- Arrow 带箭头的线
- Vector 向量
- DoubleArrow 两边都带箭头的线
- NumberLine 数轴线
思维导图如下:
各自的效果如下:
测试代码如下:
class TestLine(Scene):
def construct(self):
c1 = Circle()
all_line = [
Line(start=LEFT*2, end=RIGHT*2),
DashedLine(start=LEFT*2, end=RIGHT*2),
TangentLine(c1, alpha=1),
Arrow(start=LEFT*2, end=RIGHT*2),
Vector(),
DoubleArrow(start=LEFT*2, end=RIGHT*2),
NumberLine()
]
text_obj = [TextMobject(obj.__class__.__name__) for obj in all_line]
x = -3;y = 3
for i, j in zip(all_line, text_obj):
j.next_to(i,UP)
vg = VGroup(i, j)
vg.shift(RIGHT*x, UP*y)
if isinstance(i, TangentLine):
c1.shift(RIGHT*x, UP*y)
self.play(Write(c1), Write(vg))
else:
self.play(Write(vg))
self.wait(1)
x = x + 5
if x > 2:
x = -3
y = y-2.2