I have coded a program that provides a numerical solution for the motion of a double pendulum in python. Now I want to animate this motion using ManimCE. I do that by animating it frame by frame and rotating rod1 and rod2 by the numerically calculated angle frame by frame. But I have run into the issue that, even though I explicitly tell the animation not to do that by moving the start of rod2 to the end of rod1 frame by frame, the beginning of the second rod suddenly leaves its correct path and starts floating around.This is what it looks like. I really cannot understand why it does that, are the many calculations too much for this software? Also, if anyone has a suggestion on how to do this in a more efficient way, I would appreciate that.
This is the whole code:
from equationsolver_double_pendulum import sol1
from equationsolver_double_pendulum import fps
from manim import *
class DoublePendulum(Scene):
def construct(self):
angles_alpha = sol1.T[0]
angles_beta = sol1.T[1]
rod1 = Line([0, 2, 0], [0, 0, 0])
rod2 = Line([0, 0, 0], [0, -2, 0]).next_to(rod1.get_end(), aligned_edge=UP, buff=0)
m1 = always_redraw(lambda: Circle(radius=0.2, color=RED, fill_color=RED, fill_opacity=1).next_to(rod1.get_end(), buff=0, direction=ORIGIN))
m2 = always_redraw(lambda: Circle(radius=0.2, color=RED, fill_color=DARK_BLUE, stroke_color=DARK_BLUE, fill_opacity=1).next_to(rod2.get_end(), buff=0, direction=ORIGIN))
self.play(Create(rod1), Create(rod2))
self.play(Create(m1), Create(m2))
for angle in range(len(angles_alpha)):
if angle != 0:
self.play(Rotate(rod2,about_point=rod2.get_start(), rate_func=linear, angle=angles_beta[angle]-angles_beta[angle-1], path_arc=angles_beta[angle]-angles_beta[angle-1], run_time=1/(3*fps)))
self.play(rod2.animate.next_to(rod1.get_end(), buff=0), rate_func=linear, run_time=0.00001)
self.play(Rotate(rod1, about_point=rod1.get_start(), rate_func=linear, angle=angles_alpha[angle]-angles_alpha[angle-1], path_arc=angles_alpha[angle]-angles_alpha[angle-1], run_time=1/(3*fps)))
else:
self.play(Rotate(rod1, about_point=rod1.get_start(), rate_func=smooth, angle=angles_alpha[0], path_arc=angles_alpha[0]), run_time=1.5)
self.play(rod2.animate.next_to(rod1.get_end(), buff=0, aligned_edge=UP), rate_func=linear, run_time=0.00001)
self.play(Rotate(rod2, about_point=rod2.get_start(), rate_func=smooth, angle=angles_beta[0], path_arc=angles_beta[0]), run_time=1.5)
self.wait(3)
I am simply expecting it to animate this correctly.