马尼姆方程变换

Manim Equation Transformation

Manim 社区 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)

我正在尝试让equation_2的w^{-1}飞到equation_1的v原先占据的位置,然后变成equation_3。 equation_1 中的“1”转变成 equation_3 中的 w^{-1}。 我没有尝试进行替换转换。

如何把equation_1变成equation_3,然后把w^{-1}移到equation_1的“v”位置?

在这种特殊情况下,使用 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 的实现,有一种方法可以调整具体转换成什么。