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并移动equation_1的"v“所占位置的w^{-1}?
发布于 2022-04-20 11:56:18
在这种特殊情况下,使用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的实现,有一种方法可以精确地将什么转换成什么。
https://stackoverflow.com/questions/71938647
复制相似问题