From 2a87b8f5f12478e1894eafc8926383186a65f11c Mon Sep 17 00:00:00 2001 From: simranchhattani Date: Wed, 24 Jun 2020 15:43:06 +0530 Subject: Add files via upload --- .../vector-spaces/Vector-Spaces/Subspaces/Basis.py | 174 +++++++++++++++++++++ .../Vector-Spaces/Subspaces/Linear_Subspace.py | 42 +++++ 2 files changed, 216 insertions(+) create mode 100644 FSF-2020/linear-algebra/vector-spaces/Vector-Spaces/Subspaces/Basis.py create mode 100644 FSF-2020/linear-algebra/vector-spaces/Vector-Spaces/Subspaces/Linear_Subspace.py (limited to 'FSF-2020/linear-algebra/vector-spaces/Vector-Spaces') diff --git a/FSF-2020/linear-algebra/vector-spaces/Vector-Spaces/Subspaces/Basis.py b/FSF-2020/linear-algebra/vector-spaces/Vector-Spaces/Subspaces/Basis.py new file mode 100644 index 0000000..6d2edc8 --- /dev/null +++ b/FSF-2020/linear-algebra/vector-spaces/Vector-Spaces/Subspaces/Basis.py @@ -0,0 +1,174 @@ +from manimlib.imports import * + + +VECTORS = [[1, 2], + [-4, 2], + [-3, -3], + [3,-2], + [3,3], + [-2,1], + [-1,-3]] + +class Scene1(LinearTransformationScene): + + CONFIG = { + "include_background_plane": True, + "include_foreground_plane": False, + "show_coordinates": False, + "show_basis_vectors": True, + "basis_vector_stroke_width": 3, + + } + def construct(self): + self.setup() + ihat, jhat = self.get_basis_vectors() + labels = self.get_basis_vector_labels() + self.add(ihat, jhat) + self.add(*labels) + + self.show_vector_as_basis_sum() + self.wait(2) + + def show_vector_as_basis_sum(self): + text1 = TextMobject(r"Vector Space $\mathbb{R}^2$}").scale(0.8).shift(3*UP) + text1.add_background_rectangle() + self.play(ShowCreation(text1)) + text2 = TextMobject(r"$\mathbb{R}^2$",color=BLUE_E).scale(0.8).shift(6.5*LEFT+3.5*UP) + text3 = TextMobject(r"\text{Basis Vectors:}",r"\text{$\hat{i}$}",r"\text{,}",r"\text{$\hat{j}$}").scale(0.7).shift(2*UP+2.5*RIGHT) + text3[1].set_color(GREEN_C) + text3[3].set_color(RED_C) + + self.wait(2) + self.play(Transform(text1,text2)) + self.wait(1) + self.play(ShowCreation(text3)) + self.wait(1.7) + self.play(FadeOut(text3)) + + for i in range(len(VECTORS)): + v = self.add_vector(VECTORS[i], stroke_width = 3,color=YELLOW_D) + + linei = Line(start = ORIGIN, end = VECTORS[i][0]*RIGHT) + linei.set_color(GREEN_C) + linej = Line(start = linei.get_end(), + end = linei.get_end() + VECTORS[i][1]*UP) + linej.set_color(RED_C) + self.play(ShowCreation(linei)) + self.play(ShowCreation(linej)) + vlabel = self.get_vector_label(v, str(VECTORS[i][0]) + + r"\imath" + "+" + + str(VECTORS[i][1]) + + r"\jmath", at_tip = True) + self.play(ShowCreation(vlabel)) + + self.play(FadeOut(linei),FadeOut(linej)) + self.wait(1) + dot = Dot(v.get_end(), fill_color = v.get_stroke_color()) + self.play(ShowCreation(dot),FadeOut(v),FadeOut(vlabel)) + self.wait(0.3) + +class Scene2(LinearTransformationScene): + CONFIG = { + "num_vectors" : 16, + "start_color" : GREY, + "end_color" : YELLOW_D, + "include_background_plane": True, + "include_foreground_plane": False, + } + + def get_vectors(self): + return [ + Vector([x, y], stroke_width = 3.5) + for x in np.arange(-int(FRAME_X_RADIUS), int(FRAME_X_RADIUS)+0.5, 0.5) + for y in np.arange(-int(FRAME_Y_RADIUS), int(FRAME_Y_RADIUS)+0.5, 0.5) + ] + + def lock_in_faded_grid(self, dimness=0.7, axes_dimness=0.5): + plane = self.add_plane() + axes = plane.get_axes() + plane.fade(dimness) + axes.set_color(WHITE) + axes.fade(axes_dimness) + self.add(axes) + + def construct(self): + self.lock_in_faded_grid() + + vectors = self.get_vectors() + colors = Color(self.start_color).range_to( + self.end_color, len(vectors) + ) + for vect, color in zip(vectors, colors): + vect.set_color(color) + + vector_group = VGroup(*vectors) + self.play( + ShowCreation( + vector_group, + run_time = 3 + ) + ) + + self.wait(1) + + vectors.sort(key=lambda v: v.get_length()) + def v_to_dot(vector): + return Dot(vector.get_end(), fill_color = vector.get_stroke_color()) + self.wait() + rate_functions = [ + squish_rate_func(smooth, float(x)/(len(vectors)+2), 1) + for x in range(len(vectors)) + ] + self.play(*[ + Transform(v, v_to_dot(v), rate_func = rf, run_time = 3) + for v, rf in zip(vectors, rate_functions) + ]) + self.wait(2) + self.play_final_animation(vectors, rate_functions) + self.wait(2) + + text1 = TextMobject(" Basis is the minimum information required to ").shift(3.1*UP).scale(0.8) + text2 = TextMobject("generate the whole space.").scale(0.8).shift(2.6*UP) + + text1.add_background_rectangle() + text2.add_background_rectangle() + + + + self.play(ShowCreation(text1),ShowCreation(text2)) + + self.play(ShowCreation(self.get_basis_vectors())) + self.wait(3) + + def play_final_animation(self, vectors, rate_functions): + + h_line = Line( + FRAME_X_RADIUS*RIGHT, FRAME_X_RADIUS*LEFT, + stroke_width = 0.5, + color = BLUE_E + ) + v_line = Line( + FRAME_Y_RADIUS*UP, FRAME_Y_RADIUS*DOWN, + stroke_width = 0.5, + color = BLUE_E + ) + line_pairs = [ + VGroup(h_line.copy().shift(y), v_line.copy().shift(x)) + for v in vectors + for x, y, z in [v.get_center()] + ] + plane = NumberPlane() + + self.play( + ShowCreation(plane), + *[ + Transform(v, p, rate_func = rf) + for v, p, rf in zip(vectors, line_pairs, rate_functions) + ] + ) + self.remove(*vectors) + + + + + \ No newline at end of file diff --git a/FSF-2020/linear-algebra/vector-spaces/Vector-Spaces/Subspaces/Linear_Subspace.py b/FSF-2020/linear-algebra/vector-spaces/Vector-Spaces/Subspaces/Linear_Subspace.py new file mode 100644 index 0000000..9062b30 --- /dev/null +++ b/FSF-2020/linear-algebra/vector-spaces/Vector-Spaces/Subspaces/Linear_Subspace.py @@ -0,0 +1,42 @@ +from manimlib.imports import * +class Subspace(ThreeDScene): + + + def construct(self): + axes = ThreeDAxes() + self.set_camera_orientation(phi = 80*DEGREES,theta =110*DEGREES) + self.begin_ambient_camera_rotation(rate=0.09) + cube = Cube(stroke_width=5,color=WHITE).shift([1.5,1.5,1.5]).scale(1.5) + cube.set_fill(TEAL) + + cube.set_opacity(0.4) + line = Line(color=MAROON,set_opacity=100).shift([1.5,1.5,1.5]).scale(1.5) + plane1 = Polygon([0,0,3],[3,0,3],[3,3,0],[0,3,0]) + plane1.set_opacity(0.8) + plane1.set_fill(YELLOW) + plane1.set_color(YELLOW) + + + plane2 = Polygon([0,3,3],[3,3,3],[3,0,0],[0,0,0]) + plane2.set_opacity(0.7) + plane2.set_fill(RED) + plane2.set_color(RED) + + vgroup = VGroup(plane1,plane2,line,cube) + vgroup.shift([-2,-2,-2]) + + text = TextMobject(r"\text{The}",r"\text{line}",r"\text{representing the intersection of the two planes is a Subspace.}",opacity = 0.6).scale(0.7).shift(3*UP) + text[1].set_color(MAROON) + self.add_fixed_in_frame_mobjects(text) + self.play(ShowCreation(text)) + + + self.play(ShowCreation(cube)) + self.play(ShowCreation(plane1)) + self.play(ShowCreation(plane2)) + self.play(ShowCreation(line)) + self.wait(10) + + + + \ No newline at end of file -- cgit