How to get a line to rotate dynamically (with a moving centre) in manim?

51 Views Asked by At

I have one line rotating at a fixed point and I want another line to rotate while taking the endpoint of the first one as it's center.

So far i have the following code which makes the second line move as if the first's end was it's center but the second line doesn't rotate. What should I change to fix this?

from manim import *

class Main(Scene):
    def construct(self):
        line_length = 2

        # line1 = Line(ORIGIN, UP * line_length, color=RED)

        line1 = always_redraw(
            lambda: Line(
                ORIGIN, 
                UP * line_length, 
                color=RED
            )
        )

        # line2 = Line(UP * line_length, color=BLUE)

        line2 = always_redraw(
            lambda: Line(
                line1.get_end(), 
                line1.get_end() + UP * line_length, 
                color=BLUE
            )
        )

        self.add(line2)
        self.play(
            Rotate(line1, angle=2 * PI, about_point=ORIGIN, rate_func=linear),run_time=4
            # Rotate(line2, angle=2 * PI, about_point=line1.get_end(), rate_func=linear)
        )

I have attached the output as well for reference. What I want is for the blue line to rotate as well with the red one's endpoint as its center of rotation.

Video Output : https://youtu.be/w51C__Gye9A

0

There are 0 best solutions below