def construct(self): v = TexMobject(self.v_str) v.highlight(YELLOW) eq = TexMobject("=") coords = Matrix(["x", "y", "z"]) eq2 = eq.copy() if self.post_transform: L, l_paren, r_paren = map(TexMobject, "L()") parens = VMobject(l_paren, r_paren) parens.scale(2) parens.stretch_to_fit_height( coords.get_height() ) VMobject(L, l_paren, coords, r_paren).arrange_submobjects(buff = 0.1) coords.submobjects = [L, l_paren] + coords.submobjects + [r_paren] lin_comb = VMobject(*map(TexMobject, [ "x", self.i_str, "+", "y", self.j_str, "+", "z", self.k_str, ])) lin_comb.arrange_submobjects( RIGHT, buff = 0.1, aligned_edge = ORIGIN if self.post_transform else DOWN ) lin_comb_parts = np.array(lin_comb.split()) new_x, new_y, new_z = lin_comb_parts[[0, 3, 6]] i, j, k = lin_comb_parts[[1, 4, 7]] plusses = lin_comb_parts[[2, 5]] i.highlight(X_COLOR) j.highlight(Y_COLOR) k.highlight(Z_COLOR) everything = VMobject(v, eq, coords, eq2, lin_comb) everything.arrange_submobjects(buff = 0.2) everything.scale_to_fit_width(2*SPACE_WIDTH - 1) everything.to_edge(DOWN) if not self.post_transform: lin_comb.shift(0.35*UP) self.play(*map(Write, [v, eq, coords])) self.dither() self.play( Transform( coords.get_entries().copy(), VMobject(new_x, new_y, new_z), path_arc = -np.pi, submobject_mode = "lagged_start" ), Write(VMobject(*[eq2, i, j, k] + list(plusses))), run_time = 3 ) self.dither()
def show_formula(self): matrix = self.get_matrix() det_text = get_det_text(matrix) f_str = "=(a+b)(c+d)-ac-bd-2bc=ad-bc" formula = TexMobject(f_str) formula.next_to(det_text, RIGHT) everyone = VMobject(det_text, matrix, formula) everyone.scale_to_fit_width(2 * SPACE_WIDTH - 1) everyone.next_to(DOWN, DOWN) background_rect = BackgroundRectangle(everyone) self.play(ShowCreation(background_rect), Write(everyone)) self.wait()
def construct(self): matrix = Matrix(np.arange(9).reshape((3, 3))) vect = Matrix(list("xyz")) vect.scale_to_fit_height(matrix.get_height()) col1, col2, col3 = columns = [ Matrix(col) for col in matrix.copy().get_mob_matrix().transpose() ] coords = x, y, z = [m.copy() for m in vect.get_entries().split()] eq, plus1, plus2 = map(TexMobject, list("=++")) everything = VMobject(matrix, vect, eq, x, col1, plus1, y, col2, plus2, z, col3) everything.arrange_submobjects(buff=0.1) everything.scale_to_fit_width(2 * SPACE_WIDTH - 1) result = VMobject(x, col1, plus1, y, col2, plus2, z, col3) trips = [ (matrix, DOWN, "Transformation"), (vect, UP, "Input vector"), (result, DOWN, "Output vector"), ] braces = [] for mob, direction, text in trips: brace = Brace(mob, direction) words = TextMobject(text) words.next_to(brace, direction) brace.add(words) braces.append(brace) matrix_brace, vect_brace, result_brace = braces self.play(*map(Write, [matrix, vect]), run_time=2) self.play(Write(matrix_brace, run_time=1)) self.play(Write(vect_brace, run_time=1)) sexts = zip(matrix.get_mob_matrix().transpose(), columns, vect.get_entries().split(), coords, [eq, plus1, plus2], [X_COLOR, Y_COLOR, Z_COLOR]) for o_col, col, start_coord, coord, sym, color in sexts: o_col = VMobject(*o_col) self.play(start_coord.highlight, YELLOW, o_col.highlight, color) coord.highlight(YELLOW) col.highlight(color) self.play( Write(col.get_brackets()), Transform(o_col.copy(), col.get_entries(), path_arc=-np.pi), Transform(start_coord.copy(), coord, path_arc=-np.pi), Write(sym)) self.wait() self.play(Write(result_brace, run_time=1)) self.wait()
def show_formula(self): matrix = self.get_matrix() det_text = get_det_text(matrix) f_str = "=(a+b)(c+d)-ac-bd-2bc=ad-bc" formula = TexMobject(f_str) formula.next_to(det_text, RIGHT) everyone = VMobject(det_text, matrix, formula) everyone.scale_to_fit_width(2*SPACE_WIDTH - 1) everyone.next_to(DOWN, DOWN) background_rect = BackgroundRectangle(everyone) self.play( ShowCreation(background_rect), Write(everyone) ) self.dither()
def construct(self): i_to = TexMobject("\\hat{\\imath} \\to").highlight(X_COLOR) j_to = TexMobject("\\hat{\\jmath} \\to").highlight(Y_COLOR) k_to = TexMobject("\\hat{k} \\to").highlight(Z_COLOR) i_array = Matrix(self.col1) j_array = Matrix(self.col2) k_array = Matrix(self.col3) everything = VMobject( i_to, i_array, TexMobject("=").highlight(BLACK), j_to, j_array, TexMobject("=").highlight(BLACK), k_to, k_array, TexMobject("=").highlight(BLACK), ) everything.arrange_submobjects(RIGHT, buff=0.1) everything.scale_to_fit_width(2 * SPACE_WIDTH - 1) everything.to_edge(DOWN) i_array.highlight(X_COLOR) j_array.highlight(Y_COLOR) k_array.highlight(Z_COLOR) arrays = [i_array, j_array, k_array] matrix = Matrix( reduce(lambda a1, a2: np.append(a1, a2, axis=1), [m.copy().get_mob_matrix() for m in arrays])) matrix.to_edge(DOWN) start_entries = reduce(op.add, map(lambda a: a.get_entries().split(), arrays)) target_entries = matrix.get_mob_matrix().transpose().flatten() start_l_bracket = i_array.get_brackets().split()[0] start_r_bracket = k_array.get_brackets().split()[1] start_brackets = VMobject(start_l_bracket, start_r_bracket) target_bracketes = matrix.get_brackets() for mob in everything.split(): self.play(Write(mob, run_time=1)) self.wait() self.play( FadeOut(everything), Transform(VMobject(*start_entries), VMobject(*target_entries)), Transform(start_brackets, target_bracketes)) self.wait()
def construct(self): i_to = TexMobject("\\hat{\\imath} \\to").highlight(X_COLOR) j_to = TexMobject("\\hat{\\jmath} \\to").highlight(Y_COLOR) k_to = TexMobject("\\hat{k} \\to").highlight(Z_COLOR) i_array = Matrix(self.col1) j_array = Matrix(self.col2) k_array = Matrix(self.col3) everything = VMobject( i_to, i_array, TexMobject("=").highlight(BLACK), j_to, j_array, TexMobject("=").highlight(BLACK), k_to, k_array, TexMobject("=").highlight(BLACK), ) everything.arrange_submobjects(RIGHT, buff = 0.1) everything.scale_to_fit_width(2*SPACE_WIDTH-1) everything.to_edge(DOWN) i_array.highlight(X_COLOR) j_array.highlight(Y_COLOR) k_array.highlight(Z_COLOR) arrays = [i_array, j_array, k_array] matrix = Matrix(reduce( lambda a1, a2 : np.append(a1, a2, axis = 1), [m.copy().get_mob_matrix() for m in arrays] )) matrix.to_edge(DOWN) start_entries = reduce(op.add, map( lambda a : a.get_entries().split(), arrays )) target_entries = matrix.get_mob_matrix().transpose().flatten() start_l_bracket = i_array.get_brackets().split()[0] start_r_bracket = k_array.get_brackets().split()[1] start_brackets = VMobject(start_l_bracket, start_r_bracket) target_bracketes = matrix.get_brackets() for mob in everything.split(): self.play(Write(mob, run_time = 1)) self.dither() self.play( FadeOut(everything), Transform(VMobject(*start_entries), VMobject(*target_entries)), Transform(start_brackets, target_bracketes) ) self.dither()
def organize_matrices(self, left, right, result): equals = TexMobject("=") everything = VMobject(left, right, equals, result) everything.arrange_submobjects() everything.scale_to_fit_width(2 * SPACE_WIDTH - 1) self.add(everything)
def organize_matrices(self, left, right, result): equals = TexMobject("=") everything = VMobject(left, right, equals, result) everything.arrange_submobjects() everything.scale_to_fit_width(2*SPACE_WIDTH-1) self.add(everything)
def construct(self): matrix = Matrix(np.arange(9).reshape((3, 3))) vect = Matrix(list("xyz")) vect.scale_to_fit_height(matrix.get_height()) col1, col2, col3 = columns = [ Matrix(col) for col in matrix.copy().get_mob_matrix().transpose() ] coords = x, y, z = [m.copy() for m in vect.get_entries().split()] eq, plus1, plus2 = map(TexMobject, list("=++")) everything = VMobject( matrix, vect, eq, x, col1, plus1, y, col2, plus2, z, col3 ) everything.arrange_submobjects(buff = 0.1) everything.scale_to_fit_width(2*SPACE_WIDTH-1) result = VMobject(x, col1, plus1, y, col2, plus2, z, col3) trips = [ (matrix, DOWN, "Transformation"), (vect, UP, "Input vector"), (result, DOWN, "Output vector"), ] braces = [] for mob, direction, text in trips: brace = Brace(mob, direction) words = TextMobject(text) words.next_to(brace, direction) brace.add(words) braces.append(brace) matrix_brace, vect_brace, result_brace = braces self.play(*map(Write, [matrix, vect]), run_time = 2) self.play(Write(matrix_brace, run_time = 1)) self.play(Write(vect_brace, run_time = 1)) sexts = zip( matrix.get_mob_matrix().transpose(), columns, vect.get_entries().split(), coords, [eq, plus1, plus2], [X_COLOR, Y_COLOR, Z_COLOR] ) for o_col, col, start_coord, coord, sym, color in sexts: o_col = VMobject(*o_col) self.play( start_coord.highlight, YELLOW, o_col.highlight, color ) coord.highlight(YELLOW) col.highlight(color) self.play( Write(col.get_brackets()), Transform( o_col.copy(), col.get_entries(), path_arc = -np.pi ), Transform( start_coord.copy(), coord, path_arc = -np.pi ), Write(sym) ) self.dither() self.play(Write(result_brace, run_time = 1)) self.dither()