manim icon indicating copy to clipboard operation
manim copied to clipboard

Bug with substrings_to_isolate animation

Open sponege opened this issue 3 years ago • 2 comments

Description of bug / unexpected behavior

I'm trying to animate an equation, I want to have it animate nicely with a new equation.

from x^2 + y^2 = z^2 to 2x + 2y = 2z

Unfortunately, it doesn't even render anything else but an x in the first equation, not even the powers.

Expected behavior

I expected the number 2 (three twos that match up) to move, as well as the x, y, and z variables. The number twos move when you give a substrings_to_isolate value of "2" instead of an array, it just acts a bit funky when you provide it with an array for some reason.

How to reproduce the issue

Code for reproducing the problem
class Scene(Scene):
    def construct(self):
        title = Tex(r"Implicit differentiation")
        eq = MathTex(r"x^2+y^2=z^2", substrings_to_isolate=["2","x","y","z"]) ##MathTex(r"\sum_{n=1}^\infty \frac{1}{n^2} = \frac{\pi^2}{6}")
        diffeq = MathTex(r"2x+2y=2z", substrings_to_isolate=["2","x","y","z"])
        VGroup(title, eq, diffeq).arrange(DOWN)
        self.play(
            Write(title),
            Write(eq),
        )
        self.wait()

        self.play(
            TransformMatchingTex(eq.copy(), diffeq)
        )

        self.wait()

Additional media files

Images/GIFs

substrings_to_isolate="2": https://cdn.discordapp.com/attachments/582403919754297363/904968054243487785/scriptoutput.mp4 substrings_to_isolate=["2","x","y","z"]: https://cdn.discordapp.com/attachments/582403919754297363/904968565923401778/scriptoutput.mp4

Logs

Terminal output
PASTE HERE OR PROVIDE LINK TO https://pastebin.com/ OR SIMILAR

System specifications

System Details

The videos I provided used the online Manim Discord bot, which rendered the two videos.

Additional comments

I wonder if substrings_to_isolate only supports one character rather than an array of characters?

sponege avatar Apr 08 '22 21:04 sponege

This seems to be an issue with the Write animation, which seems to only render the first submobject. Using FadeIn doesn't show the same behaviour. I'm not familiar enough with the internals of manim to help further, unfortunately.

niklebedenko avatar May 05 '22 15:05 niklebedenko

I got the first equation to display correctly by using "^2" instead of "2" in substrings_to_isolate: eq = MathTex("x^2+y^2=z^2", substrings_to_isolate=["^2","x","y","z"])

But TransformMatchingTex does not consider the superscript ^2 and the normal 2 as matching (different tex_strings) and fades in and out instead of transforming. TransformMatchingShapes also results in the same effect, which should mean the superscript ^2 and the normal 2 are different after normalization.

Reference manual entry for TransformMatchingShapes:

Two submobjects match if the hash of their point coordinates after normalization (i.e., after translation to the origin, fixing the submobject height at 1 unit, and rounding the coordinates to three decimal places) matches.

EDIT:

I got it working by modifying the source file (get_object_key() in manim\animation\transform_matching_parts.py) to remove ^ from the tex_strings so that they match. Not a proper solution by any means.

Result: https://user-images.githubusercontent.com/105051287/167185705-8ba9627e-5098-4698-acc1-12c988ac2ce8.mp4

EDIT 2:

it just acts a bit funky when you provide it with an array for some reason.

It is acting funky because making x and 2 substrings also causes ^ to become a substring which Manim does not seem to like. It has nothing to do with providing a list for substrings_to_isolate.

I wonder if substrings_to_isolate only supports one character rather than an array of characters?

substrings_to_isolate does support arrays. It is just not working in this case because of the lone ^.

hargol avatar May 06 '22 17:05 hargol