Can I use Mathematica to generate math animations instead of Manim?

77 views Asked by At

I'm a beginner in making videos. Some math animations are needed and I was wondering if I could use Mathematica & DaVinci instead of Manim.

I tried to generate a very simple animation about finite integrals.

(* Basic Settings *)
Needs["MaTeX`"];
ConfigureMaTeX[]
SetDirectory[NotebookDirectory[]];

(* Video Settings *)
frameRate = 60; videoSize = Large;
imageGap = 1/frameRate;

(* Ticks Settings *)
ticks = 0.2;
latexTicks[min_, max_, gap_] := 
  Table[{i, MaTeX[i]}, {i, min, max, gap}];
latexTicks[min_, max_] := latexTicks[min, max, ticks];

(* Movement Function *)
s[a_, b_, h_, x_] := \[Piecewise] {
    {h/a x, 0 <= x < a},
    {h, a < x <= (a + b)},
    {h - h /a (x - a - b), (a + b) < x <= (2 a + b)},
    {0, x > (2 a + b)}
   };
pos[x_] := NIntegrate[s[1, 2, 1, t], {t, 0, 4 x}]/3;
sMove[{a_, b_}, t_] := \[Piecewise] {
    {(b - a) pos[t] + a, a != b},
    {a, a == b}
   };

(* Core Function*)
f[{a1_, b1_}] := Column[{
    MaTeX[
     Row[{Text["The Area under the Curve ="], 
       HoldForm[Integrate[h[x], {x, a, b}]], "=", 
       NIntegrate[h[x], {x, a1, b1}]}],
     "Preamble" -> {"\\usepackage{ctex}"}, FontSize -> 14],
    temp = 
     Show[Plot[h[x], {x, leftR, rightR}, PlotRange -> {-(1/2), 1}, 
       Ticks -> {latexTicks[leftR, rightR, \[Pi]], latexTicks}, 
       ImageSize -> videoSize,
       Epilog -> {Text[MaTeX["x=a"], {a1 + 0.2, -0.4}, {-1, 0}], 
         Text[MaTeX["x=b"], {b1 + 0.2, -0.4}, {-1, 0}]}],
      ParametricPlot[{{a1, t}, {b1, t}}, {t, -1/2, 2}, 
       PlotStyle -> Orange]];
    If[a1 == b1, temp, 
     Show[temp, 
      Plot[h[x], {x, a1, b1}, PlotStyle -> Opacity[0], 
       Filling -> {1 -> {Axis, {{Yellow, Opacity[0.5]}, {Orange, 
             Opacity[0.5]}}}}]]]}];

(* Manipulation*)
h[x_] := \[Piecewise] {
    {(Sin[x]/x), x != 0},
    {1, x == 0}
   };
leftR = -(6/2) \[Pi]; rightR = 
 6/2 \[Pi]; defaultA = -\[Pi]; defaultB = \[Pi];
Manipulate[f[{a1, b1}],
 {{a1, defaultA, MaTeX["a"]}, leftR, rightR, 
  Appearance -> "Labeled"},
 {{b1, defaultB, MaTeX["b"]}, leftR, rightR, Appearance -> "Labeled"}]

(* Video Generation*)
cGenerator[{p1_, p2_}, {q1_, q2_}, time_] := 
  ParallelTable[
   N[{sMove[{p1, p2}, t], sMove[{q1, q2}, t]}], {t, 0, 1, 1/(
    time*frameRate)}];
t1 = cGenerator[{-2 \[Pi], -2 \[Pi]}, {-3 \[Pi], 3 \[Pi]}, 2.3];
t2 = cGenerator[{-2 \[Pi], 2 \[Pi]}, {3 \[Pi], -\[Pi]}, 1.4];
t3 = cGenerator[{2 \[Pi], \[Pi]}, {-\[Pi], -\[Pi]}, 1];
t = Join[t1, t2, t3];
Print["Tables Generated Successfully!"];
Export["test1.mov", ParallelTable[f[i], {i, t}], 
  FrameRate -> frameRate] // AbsoluteTiming
Print["First video Generated Successfully!"];
ClearMaTeXCache[];
Export["test2.mov", Table[f[i], {i, t}], 
  FrameRate -> frameRate] // AbsoluteTiming
Print["Second video Generated Successfully!"];
ClearMaTeXCache[];

The result is good. But it comes with a few problems:

  1. the speed. it took 112 seconds to render this video. But in manim, it only needed 30 seconds to generate a similar one. I guess it's the problem with MaTeX[]. But when I replaced MaTeX[] with Rasterize[TraditionalForm[]], the result is not aligned very well and it took 58 seconds. So is there any ways to increase the speed? And despite MaTeX, is there anyways to create TeX-like formulas and texts in mathematica?
  2. the animation. it's somehow hard for me to do all the transitions and effects in Mathematica. (Although I don't know how to create such effects in manim, I think it's relatively easier) For example, if I want to create a effect that a curve gradually appears on the screen, the only way I can think of is to create the curve in Mathematica and to use masks in DaVinci. Is there any other ways to do this? And how to create tweens between formulas?
  3. the lack of tools Although it might be he same case in manim, but there's no frame editor in mathematica. And it's hard to control the speed and to add the key frames
  4. Is this a right choice? I'm trying to be a uploader, but I just entered college and I'm learning all the tools. Is DaVinci & Mathematica decent tools for making such videos?

Sorry if my English may sounds weird because it's not my native language. And really, great thanks if anyone can give me any advice. a frame of the video generated using MaTeX

0

There are 0 answers