马尼姆方程变换

Sup*_*len 3 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)
Run Code Online (Sandbox Code Playgroud)

我试图让方程_2 中的 w^{-1} 飞入方程_1 中以前由 v 占据的位置并转换为方程_3。相反,方程_1 中的“1”会转换为方程_3 中的 w^{-1}。我并不是想进行替换变换。

如何将equation_1转换为equation_3并将w^{-1}移动到equation_1的“v”占据的位置?

小智 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,
            )
        )
Run Code Online (Sandbox Code Playgroud)

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