You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Manim Community的TracedPath类时路径出现尖角的解决方法

解决TracedPath路径尖锐的方法

核心原因是run_time=0.4过短,TracedPath默认采样间隔下生成的路径点太少,导致线条尖锐。可以通过以下方式优化:

1. 减小TracedPath的采样间隔

初始化TracedPath时添加dt参数,设置更小的时间间隔,让Manim更频繁地采样Dot位置,生成更多路径点:

tr = TracedPath(
    d.get_center,
    dissipating_time=3,
    stroke_opacity=[0, 1],
    stroke_color=BLUE+GREEN,
    dt=0.01  # 默认dt为0.05,调小后采样更密集
)

2. 调整动画速率函数

将动画的rate_func设为平滑过渡类型,让ValueTracker的变化更平缓,间接让路径采样更均匀:

self.play(
    vt1.animate.set_value(2*PI),
    run_time=.4,
    rate_func=smooth
)

3. 适当延长动画时长(可选)

如果场景允许,稍微增加run_time(比如设为0.8),也能自然增多采样点,让路径更平滑。

优化后的完整代码示例:

from manim import *
import numpy as np

class scene(Scene):
    def construct(self):
        vt1 = ValueTracker(0)
       
        d = always_redraw(lambda : Dot().shift(np.array((2*np.cos(vt1.get_value()), 2*np.sin(vt1.get_value()), 0.0))))

        tr = TracedPath(
            d.get_center,
            dissipating_time=3,
            stroke_opacity=[0, 1],
            stroke_color=BLUE+GREEN,
            dt=0.01
        )

        self.wait(.5)
        self.play(FadeIn(d, shift=UP), run_time=.2)
        self.add(tr)
        self.play(vt1.animate.set_value(2*PI), run_time=.4, rate_func=smooth)

内容的提问来源于stack exchange,提问作者Jamukha

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.18 15:55:20