Manim 方程式转换

3

Manim Community v0.15.1

class Equation_Transformation_Bug(Scene):
    def construct(self):
        equation_1 = MathTex("w", "\\times","v", "=", "1")
        equation_1.shift(UP*2).scale(2)
        equation_2 = MathTex("v", "=", "w^{-1}")
        equation_2.scale(2)
        equation_3 = MathTex("w", "\\times","w^{-1}", "=", "1")
        equation_3.shift(UP*2).scale(2)

        self.play(Write(equation_1), Write(equation_2))
        self.wait(2)
        self.play(FadeOut(equation_1[2]))

        self.play(*[
            Transform(
                equation_2.get_part_by_tex("w^{-1}"),
                equation_3.get_part_by_tex("w^{-1}")                
            )
        ] + [
            Transform(
                equation_1.get_part_by_tex(tex),
                equation_3.get_part_by_tex(tex)
            )
            for tex in ("w", "\\times","=", "1")
        ])
        self.wait(1)

我正在尝试将方程2中的w^{-1}转移到曾被方程1中的v占据的位置,并转换为方程3。 而方程1中的“1”则转换成了方程3中的w^{-1}。 我不是在尝试进行替换变换。 如何将方程1转换为方程3并将方程1中“v”所在的位置移动到由w^{-1}占据的位置?
1个回答

5
一种使用 TransformMatchingShapes 方法在这种特定情况下效果还不错:
class Eq(Scene):
    def construct(self):
        equation_1 = MathTex("w", "\\times","v", "=", "1")
        equation_1.shift(UP*2).scale(2)
        equation_2 = MathTex("v", "=", "w^{-1}")
        equation_2.scale(2)
        equation_3 = MathTex("w", "\\times","w^{-1}", "=", "1")
        equation_3.shift(UP*2).scale(2)

        self.play(Write(equation_1), Write(equation_2))
        self.wait(2)
        self.play(FadeOut(equation_1[2]))

        self.play(
            TransformMatchingShapes(
                VGroup(equation_1[0:2], equation_1[3:], equation_2[2].copy()),
                equation_3,
            )
        )

如果您有无法唯一匹配的形状,请查看TransformMatchingShapes的实现,这里有一种方法可以调整精确地将什么转换为什么。


这个很好地运作了。如果您知道为什么我的方法没有产生您提供的结果,我想知道原因。 - SuperUser_Vermeylen
1
@SuperUser_Vermeylen 确定:问题出在 get_part_by_tex 上,它默认返回第一个包含查询字符串的子字符串。如果您将调用更改为 .get_part_by_tex(tex, substring=False),则动画也可以正常渲染! - Benjamin Hackl

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接