summaryrefslogtreecommitdiff
path: root/FSF-2020/calculus-of-several-variables/geometry-of-planes-and-curves/tnb-frame-and-serret-frenet-formulae/file7_fs3.py
blob: 698ca749b22b125f7c6483854db0217f96d92942 (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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
from manimlib.imports import *

class f(SpecialThreeDScene):
    CONFIG = {
         "axes_config": {
            "x_min": -5,
            "x_max": 5,
            "y_min": -5,
            "y_max": 5,
            "z_min": -4,
            "z_max": 4,
            "x_axis_config": {
                "tick_frequency": 100,
            },
            "y_axis_config": {
                "tick_frequency": 100,
            },
            "z_axis_config": {
                "tick_frequency": 100,
            },
            "num_axis_pieces": 1,
        }
    }
    def construct(self):
        axes = ThreeDAxes(**self.axes_config)
        text = TextMobject(r'$r(t) = \left\langle\sinh{t}, \cosh{t}, 2t\right\rangle$').scale(0.7).shift(3*UP + 3*LEFT)
        self.set_camera_orientation(phi = 75*DEGREES, theta=225*DEGREES)



        figure = ParametricFunction(
            lambda t: np.array([
                np.sinh(t),
                np.cosh(t),
                2*t
                ]), t_min = -3, t_max = 3, color=ORANGE
            ).scale(0.5).move_to(ORIGIN)

        dot = Dot(color=RED)
        alpha = ValueTracker(0)
        t = alpha.get_value

        vector_x = self.get_binormal_vector(t()%1, figure,scale=2)
        vector_y = self.get_normal_vector(t(),figure,scale=2)
        vector_z = self.get_tangent_vector(t(), figure, scale=2)

        vector_x.add_updater(
            lambda m: m.become(
                    self.get_binormal_vector(t()%1,figure,scale=2)
                )
            )
        vector_y.add_updater(
            lambda m: m.become(
                    self.get_normal_vector(t(),figure,scale=2)
                )
            )
        vector_z.add_updater(
            lambda m: m.become(
                    self.get_tangent_vector(t(),figure,scale=2)
                )
            )
        dot.add_updater(
        lambda m: m.move_to(vector_x.get_start())
        )
        def curvature(t):
            r = np.array([np.sinh(t), np.cosh(t), 2*t])
            rp = np.array([np.cosh(t), np.sinh(t), 2])
            rpp = np.array([np.sinh(t), np.cosh(t), 0])
            cp = np.cross(rp, rpp)
            k = cp / (np.dot(rp, rp)**1.5)
            return abs(k[0])

        def torsion(t):
            r = np.array([np.sinh(t), np.cosh(t), 2*t])
            rp = np.array([np.cosh(t), np.sinh(t), 2])
            rpp = np.array([np.sinh(t), np.cosh(t), 0])
            n = rpp / np.dot(rpp, rpp)
            dbdt = np.array([2*np.sinh(t), 2*np.cosh(t), 0])
            tor = np.dot(dbdt, n)
            return tor



        k = curvature(0.3)
        k = "{:.2f}".format(k)
        tor = torsion(0.3)
        tor = "{:.2f}".format(tor)
        kt1 = TextMobject(rf'At the given point, \\ $\kappa =$ {k} \\').scale(0.7).shift(3*UP + 4*RIGHT)
        kt2 = TextMobject('$\implies \kappa$',r'$T$',r' is scaled as:').scale(0.7).next_to(kt1, DOWN, buff=0.1)
        kt2.set_color_by_tex_to_color_map({
        '$T$': YELLOW
        })
        tbt1 = TextMobject(rf'At the given point, \\ $\tau =$ {tor} \\').scale(0.7).shift(3*UP + 4*RIGHT)
        tbt2 = TextMobject(r'$\implies \tau$',r'$B$',r' is scaled as:').scale(0.7).next_to(tbt1, DOWN, buff=0.1)
        tbt2.set_color_by_tex_to_color_map({
        '$B$': GREEN_E
        })
        ft = TextMobject(r'$\frac{dN}{ds}$',r'$ = -\kappa$',r'$T$', r'$ + \tau$',r'$B$ \\', r'and is given as:').scale(0.7).shift(3*UP + 4*RIGHT)
        ft.set_color_by_tex_to_color_map({
        r'$\frac{dN}{ds}$': GREEN_SCREEN,
        '$T$': YELLOW,
        r'$B$ \\': GREEN_E
        })

        self.add_fixed_in_frame_mobjects(text)
        self.play(FadeIn(figure), FadeIn(axes), FadeIn(text))
        # self.begin_ambient_camera_rotation(rate = 0.13)
        self.wait(1)
        self.add(vector_x, vector_y,vector_z,dot)
        self.play(alpha.increment_value, 0.3, run_time=10, rate_func=rush_from)
        self.wait(1)
        # self.stop_ambient_camera_rotation()
        # self.move_camera(phi = 75*DEGREES, theta=225*DEGREES)
        square = Rectangle(width=3.2, fill_color=WHITE, fill_opacity=0.3, color=RED_C).rotate(40*DEGREES).shift(0.8*DOWN+1.2*RIGHT)
        mat = [[0.7, 0.3], [1.0, -0.7]]
        square = square.apply_matrix(mat).rotate(17*DEGREES).shift(2.1*DOWN+RIGHT)
        tl, nl, bl = TextMobject(r'$T$', color=YELLOW).shift(2.8*RIGHT+0.5*DOWN), TextMobject(r'$N$', color=BLUE).shift(RIGHT), TextMobject(r'$B$', color=GREEN_E).shift(0.6*LEFT+0.5*DOWN)
        self.add_fixed_in_frame_mobjects(tl, nl, bl)
        self.play(FadeIn(VGroup(*[tl, nl, bl])))
        self.wait(3)
        self.add_fixed_in_frame_mobjects(square)
        self.play(FadeIn(square), FadeOut(VGroup(*[tl, nl, bl])))
        self.wait(2)
        self.add_fixed_in_frame_mobjects(kt1)
        self.play(FadeIn(kt1))
        self.wait(2)
        self.add_fixed_in_frame_mobjects(kt2)
        self.play(FadeIn(kt2))
        self.wait(2)
        kt = self.get_tangent_vector(0.3, figure, scale = -4*float(k))
        tb = self.get_binormal_vector(0.3, figure, scale = 2*float(tor))
        self.play(
        ReplacementTransform(vector_z, kt)
        )
        self.wait(3)
        self.add_fixed_in_frame_mobjects(tbt1)
        self.play(FadeOut(VGroup(*[kt1, kt2])), FadeIn(tbt1))
        self.wait(2)
        self.add_fixed_in_frame_mobjects(tbt2)
        self.play(FadeIn(tbt2))
        self.wait(2)
        self.play(
        ReplacementTransform(vector_x, tb)
        )
        self.wait(2)
        self.add_fixed_in_frame_mobjects(ft)
        self.play(FadeOut(VGroup(*[tbt1, tbt2])), FadeIn(ft))
        self.wait(2)
        dnds = Arrow(dot.get_center() + np.array([-0.1,-0.25,0]), np.array([-4,-1,2]), color=GREEN_SCREEN)
        dndsl = TextMobject(r'$\frac{dN}{ds}$', color=GREEN_SCREEN).shift(2.5*LEFT + 1.2*UP)
        self.add_fixed_in_frame_mobjects(dndsl)
        self.play(FadeIn(dnds), FadeIn(dndsl))
        self.wait(5)
        self.play(FadeOut(VGroup(*[square, dot,vector_y, dnds, dndsl, text, ft, tb, kt])))
        self.play(FadeOut(figure), FadeOut(axes))


    def get_binormal_vector(self, proportion, curve, dx=0.001, scale=1):
        t = proportion
        coord_i = curve.point_from_proportion(proportion)
        rprime = np.array([np.cosh(t), np.sinh(t), 2])
        T = rprime / np.sqrt(np.dot(rprime, rprime))
        rpp = np.array([np.sinh(t), np.cosh(t), 0])
        n = rpp / np.dot(rpp, rpp)
        # b = (np.cross(T, n)[0] - 0.5, np.cross(T, n)[1], coord_i[2] + 1)
        b = np.cross(T, n)
        # coord_f = curve.point_from_proportion(proportion + dx)
        coord_f = b
        reference_line = Line(coord_i,coord_f)
        unit_vector = reference_line.get_unit_vector() * scale
        vector = Arrow(coord_i , coord_i + unit_vector, color = GREEN_E, buff=0)
        return vector

    def get_normal_vector(self, proportion, curve, dx=0.001, scale=1):
        coord_i = curve.point_from_proportion(proportion)
        coord_f = curve.point_from_proportion(proportion + dx)
        t = proportion.copy()/7
        rpp = np.array([np.sinh(t), np.cosh(t), 0])
        length = np.sqrt(np.dot(rpp, rpp))
        length = 1/(1 + np.exp(-length))
        reference_line = Line(coord_i,coord_f).rotate(PI/2).set_width(length).scale(2)
        unit_vector = reference_line.get_unit_vector() * scale
        vector = Arrow(coord_i, coord_i + unit_vector, color = BLUE, buff=0)
        return vector

    def get_tangent_vector(self, proportion, curve, dx=0.001, scale=1):
        coord_i = curve.point_from_proportion(proportion)
        coord_f = curve.point_from_proportion(proportion + dx)
        reference_line = Line(coord_i,coord_f).scale(2)
        if scale < 0:
            reference_line = Line(coord_i,coord_f).scale(2).rotate(360*DEGREES)
        unit_vector = reference_line.get_unit_vector() * scale
        vector = Arrow(coord_i, coord_i + unit_vector, color = YELLOW, buff=0)
        return vector