画向量最常用的三件套:NumberPlane 铺坐标网格、Dot 标点、Arrow 画从起点到终点的箭头,再用 Text 标注坐标。示例把从 (0,0) 到 (2,2) 的向量完整画了出来。
完整代码
1 2 3 4 5 6 7 8 9 10 11 12
| from manim import * import numpy as np class VectorArrow(Scene): def construct(self): dot = Dot(ORIGIN) arrow = Arrow(ORIGIN, [2, 2, 0], buff=0) numberplane = NumberPlane() origin_text = Text('(0, 0)').next_to(dot, DOWN) tip_text = Text('(2, 2)').next_to(arrow.get_end(), RIGHT) self.play(*[FadeIn(_o) for _o in [numberplane, dot, arrow, origin_text, tip_text]], run_time=1.0) self.wait(1) self.wait(3.60)
|
演示视频
下载 Python 脚本
要点
Arrow(ORIGIN, [2, 2, 0], buff=0) 里 buff=0 让箭头紧贴起点
Text('(0, 0)') 是普通文本,含 LaTeX 公式要换 MathTex
- 纯
self.add() 的静态场景必须补 self.wait(),否则不输出视频
代码来源:Manim Community 官方 Example Gallery 示例 VectorArrow,已在 Manim CE 0.20.1 实跑验证并生成上方视频。
主观感受,仅供参考。本文采用 本文采用 CC BY-NC-SA 4.0 许可 协议,
完整转载请注明来自
数学动画引擎。