summaryrefslogtreecommitdiff
path: root/FSF-2020/linear-algebra/linear-transformations/Orthonormal-Basis/file2_sum_of_projections_part1.py
blob: 141e99bb015d5cc852d251b0f9d5a95800f909d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
from manimlib.imports import *
class LinearTrans(LinearTransformationScene):
    CONFIG = {
    "show_basis_vectors": True,
    "basis_vector_stroke_width": 1,
    "leave_ghost_vectors": False,
    "show_coordinates": True,
    }
    
    def construct(self):

        self.setup()

        matrix = [[0.6,-0.8],[0.8,0.6]]
        self.apply_matrix(matrix)

        self.wait(2)
        orthonormal = TextMobject(r"These are 2 orthonormal vectors($v_1$ and $v_2$)")
        orthonormal.scale(0.7)
        orthonormal.move_to(DOWN+LEFT*3.5)
        orthonormal.add_background_rectangle()
        v1 = TextMobject(r"$v_1$")
        v1.scale(0.75)
        v1.set_color(X_COLOR)
        v1.move_to(0.75*UP+RIGHT)
        v1.add_background_rectangle()
        v2 = TextMobject(r"$v_2$")
        v2.scale(0.75)
        v2.set_color(Y_COLOR)
        v2.move_to(0.75*UP+LEFT*1.25)
        v2.add_background_rectangle()
        self.play(Write(orthonormal))
        self.play(Write(v1),Write(v2))
        self.wait()
        self.play(FadeOut(orthonormal), FadeOut(v1), FadeOut(v2))
        
        arrow = Arrow(start = ORIGIN,end = 3*RIGHT+UP)
        arrow.scale(1.2)
        arrow.set_color(BLUE)
        arrow.apply_matrix(matrix)
        text3 = TextMobject("v")
        text3.move_to(3.2*UP+1.2*RIGHT)
        text3.add_background_rectangle()
        self.play(ShowCreation(arrow),Write(text3))
        self.wait()
        v_cor = TextMobject("(1 , 3)")
        v_cor.move_to(3.2*UP+1.3*RIGHT)
        v_cor.set_color(BLUE)
        v_cor.scale(0.75)
        v_cor.add_background_rectangle()
        self.play(Transform(text3,v_cor))

        line1 = DashedLine(start = 1*UP+3*RIGHT, end = 3*RIGHT)
        line2 = DashedLine(start = 1*UP+3*RIGHT, end = UP)
        line1.apply_matrix(matrix)
        line2.apply_matrix(matrix)
        self.play(ShowCreation(line1),ShowCreation(line2),run_time = 2)
        
        v1 = Arrow(start = ORIGIN,end = 3*RIGHT+UP)
        v1.scale(1.2)
        v1.set_color(BLUE)
        v1.apply_matrix(matrix)
        arrow1 = Arrow(start = ORIGIN,end = 3*RIGHT)
        arrow1.scale(1.2)
        arrow1.set_color("#6B8E23")
        arrow1.apply_matrix(matrix)
        self.play(Transform(v1,arrow1))
        v1_cor = TextMobject(r"$<v,v_1> v_1$")
        v1_cor.move_to(2.5*UP+3*RIGHT)
        v1_cor.scale(0.75)
        v1_cor.add_background_rectangle()
        self.play(Write(v1_cor))
        self.wait(0.5)
        text1 = TextMobject("(1.8 , 2.4)")
        text1.move_to(2.1*UP+2.5*RIGHT)
        text1.scale(0.75)
        text1.set_color("#6B8E23")
        text1.add_background_rectangle()
        self.play(Transform(v1_cor,text1))

        v2 = Arrow(start = ORIGIN,end = 3*RIGHT+UP)
        v2.scale(1.2)
        v2.set_color("#8b0000")
        v2.apply_matrix(matrix)
        arrow2 = Arrow(start = ORIGIN,end = UP)
        arrow2.scale(2.1)
        arrow2.set_color("#8b0000")
        arrow2.apply_matrix(matrix)
        self.wait(0.5)
        self.play(Transform(v2,arrow2))
        self.wait(0.5)
        v2_cor = TextMobject(r"$<v,v_2> v_2$")
        v2_cor.move_to(0.75*UP+2.5*LEFT)
        v2_cor.scale(0.75)
        v2_cor.add_background_rectangle()
        self.play(Write(v2_cor))
        self.wait(0.5)
        text2 = TextMobject("(-0.8 , 0.6)")
        text2.move_to(0.75*UP+1.75*LEFT)
        text2.scale(0.75)
        text2.set_color("#8b0000")
        text2.add_background_rectangle()
        self.play(Transform(v2_cor,text2))

        self.wait()

        self.play(ApplyMethod(v2.move_to,1.4*RIGHT+2.7*UP),FadeOut(v1_cor),FadeOut(v2_cor),FadeOut(v_cor))

        self.wait()

        ending = TextMobject(r"$v = <v,v_1> v_1 + <v,v_2> v_2$")
        ending.scale(0.7)
        ending.move_to(DOWN)
        ending.add_background_rectangle()
        self.play(Write(ending))
        self.wait()
        self.play(FadeOut(ending))
        
        ending = TextMobject(r"$\left[ \begin{array} {c} 1\\ 3 \end{array}\right] = \left[ \begin{array} {c}1.8 \\ 2.4 \end{array}\right] + \left[ \begin{array} {c} -0.8\\ 0.6 \end{array}\right]$")
        ending.scale(0.7)
        ending.move_to(DOWN)
        ending.add_background_rectangle()
        self.play(Write(ending))
        self.wait()
        self.play(FadeOut(ending))

        ending = TextMobject(r"$v$ is the sum of projections on the orthonormal vectors")
        ending.scale(0.7)
        ending.move_to(DOWN)
        ending.add_background_rectangle()
        self.play(Write(ending))
        self.wait()
        self.play(FadeOut(ending))