Skip to content

Instantly share code, notes, and snippets.

@uwezi
Last active October 17, 2024 16:21
Show Gist options
  • Save uwezi/fb94a62915a90f2289cb0c78cb9bb61a to your computer and use it in GitHub Desktop.
Save uwezi/fb94a62915a90f2289cb0c78cb9bb61a to your computer and use it in GitHub Desktop.
[Triangle construction] Part of a proof for sin(x)sin(y). #manim #triangle #geometry #trigonometry #animation
from manim import *
class sinxsiny(Scene):
def construct(self):
O = Dot([-3,-3.0,0], color=YELLOW, radius=0.05)
A = Dot([3,-3.0,0], color=YELLOW, radius=0.05)
lbl_O = MathTex(r"O").next_to(O,LEFT)
lbl_A = MathTex(r"A").next_to(A,RIGHT)
x = 35*DEGREES
y = 20*DEGREES
OA = Line(O.get_center(),A.get_center())
self.play(Create(OA))
self.play(Create(O),Write(lbl_O))
self.play(Create(A),Write(lbl_A))
OB = Line(O.get_center(),A.get_center())
B = always_redraw(lambda:
Dot(OB.get_end(), color=YELLOW, radius=0.05)
)
lbl_B = always_redraw(lambda:
MathTex(r"B").next_to(B.get_center(),RIGHT)
)
AB = always_redraw(lambda:
Line(A.get_center(),B.get_center())
)
ang_x = always_redraw(lambda:
Arc(radius=0.5, start_angle=0, angle=OB.get_angle()).shift(O.get_center())
)
self.play(Create(OB),Create(AB),Create(ang_x))
self.play(Create(B),Write(lbl_B))
self.play(
OB.animate.rotate(angle=x,about_point=O.get_center()).scale(1/np.cos(x),about_point=O.get_center())
)
lbl_x = MathTex(r"x").rotate(-x/2).shift(0.7*RIGHT).rotate(x/2,about_point=ORIGIN).shift(O.get_center())
self.play(Write(lbl_x))
dummy = OB.copy().rotate(angle=-x,about_point=O.get_center())
OC = dummy.copy()
C = always_redraw(lambda:
Dot(OC.get_end(), color=YELLOW, radius=0.05)
)
lbl_C = always_redraw(lambda:
MathTex(r"C").next_to(C.get_center(),RIGHT)
)
BC = always_redraw(lambda:
Line(OC.get_end(),dummy.get_end())
)
ang_y = always_redraw(lambda:
Arc(radius=1, start_angle=dummy.get_angle(), angle=OC.get_angle()-dummy.get_angle()).shift(O.get_center())
)
self.play(
Create(dummy),Create(OC),Create(BC),
Write(lbl_C),Create(C),
Create(ang_y)
)
self.play(
OC.animate.rotate(angle=y,about_point=O.get_center()).scale(1/np.cos(y),about_point=O.get_center())
)
lbl_y = always_redraw(lambda:
MathTex(r"y").rotate(-dummy.get_angle()-x/2).shift(1.2*RIGHT).rotate(+dummy.get_angle()+y/2,about_point=ORIGIN).shift(O.get_center())
)
self.play(Write(lbl_y))
self.wait()
self.play(
Rotate(
VGroup(dummy,OC,BC),
angle=x,
about_point=O.get_center()
)
)
E = Dot(point=[C.get_center()[0],A.get_center()[1],0], color=YELLOW, radius=0.05)
lbl_E = MathTex(r"E").next_to(E,DOWN,buff=0.05)
D = Dot(point=[C.get_center()[0],B.get_center()[1],0], color=YELLOW, radius=0.05)
lbl_D = MathTex(r"D").next_to(D,LEFT)
CE = Line(C.get_center(),E.get_center())
BD = Line(B.get_center(),D.get_center())
self.play(Create(CE))
self.play(Create(E),Write(lbl_E))
self.play(Create(BD))
self.play(Create(D),Write(lbl_D))
ang_x.suspend_updating()
lbl_x.suspend_updating()
ang_y.suspend_updating()
lbl_y.suspend_updating()
ang_x2 = VGroup(ang_x.copy(),lbl_x.copy())
self.play(
ang_x2.animate.shift(C.get_center()-O.get_center())
)
self.play(
Rotate(ang_x2, -PI/2, about_point=C.get_center())
)
ang_x3 = ang_x2.copy()
self.play(
ang_x3.animate.shift(B.get_center()-C.get_center())
)
self.play(
Rotate(ang_x3, -PI/2, about_point=B.get_center())
)
self.wait()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment