要留下运动轨迹,不必用 TracedPath 也行:准备一个空 VMobject,每帧把点当前坐标追加成折线拐点。示例让点绕右侧点转半圈、再上移左移,轨迹随之延伸。
完整代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| from manim import * class PointWithTrace(Scene): def construct(self): path = VMobject() dot = Dot() path.set_points_as_corners([dot.get_center(), dot.get_center()]) def update_path(path): previous_path = path.copy() previous_path.add_points_as_corners([dot.get_center()]) path.become(previous_path) path.add_updater(update_path) self.play(*[FadeIn(_o) for _o in [path, dot]], run_time=1.0) self.play(Rotating(dot, angle=PI, about_point=RIGHT, run_time=2)) self.wait() self.play(dot.animate.shift(UP)) self.play(dot.animate.shift(LEFT)) self.wait()
|
演示视频
下载 Python 脚本
要点
set_points_as_corners([...]) 用拐点定义折线,不自动平滑
path.become(previous_path) 是「整条路径替换」,避免点集无限追加
- 轨迹对象必须在点之前加入场景,否则会被后加入的对象盖住
代码来源:Manim Community 官方 Example Gallery 示例 PointWithTrace(MIT),已在 Manim CE 0.20.1 实跑验证并生成上方视频。
主观感受,仅供参考。本文采用 本文采用 CC BY-NC-SA 4.0 许可 协议,
完整转载请注明来自
数学动画引擎。