def get_det(self): matrix = Matrix(np.array([ ["\\hat{\\imath}", "\\hat{\\jmath}", "\\hat{k}"], ["v_%d"%d for d in range(1, 4)], ["w_%d"%d for d in range(1, 4)], ]).T) matrix.highlight_columns(X_COLOR, V_COLOR, W_COLOR) matrix.get_mob_matrix()[1, 0].highlight(Y_COLOR) matrix.get_mob_matrix()[2, 0].highlight(Z_COLOR) Group(*matrix.get_mob_matrix()[1, 1:]).shift(0.15*DOWN) Group(*matrix.get_mob_matrix()[2, 1:]).shift(0.35*DOWN) det_text = get_det_text(matrix) det_text.add(matrix) return det_text
def get_det(self): matrix = Matrix( np.array([ ["\\hat{\\imath}", "\\hat{\\jmath}", "\\hat{k}"], ["v_%d" % d for d in range(1, 4)], ["w_%d" % d for d in range(1, 4)], ]).T) matrix.highlight_columns(X_COLOR, V_COLOR, W_COLOR) matrix.get_mob_matrix()[1, 0].highlight(Y_COLOR) matrix.get_mob_matrix()[2, 0].highlight(Z_COLOR) VGroup(*matrix.get_mob_matrix()[1, 1:]).shift(0.15 * DOWN) VGroup(*matrix.get_mob_matrix()[2, 1:]).shift(0.35 * DOWN) det_text = get_det_text(matrix) det_text.add(matrix) return det_text
def construct(self): v_tex, w_tex, p_tex = get_vect_tex(*"vwp") vector_word = TextMobject("Vector:") transform_word = TextMobject("Dual transform:") cross = TexMobject(p_tex, "=", v_tex, "\\times", w_tex) for tex, color in zip([v_tex, w_tex, p_tex], [U_COLOR, W_COLOR, P_COLOR]): cross.highlight_by_tex(tex, color) input_array_tex = matrix_to_tex_string(["x", "y", "z"]) func = TexMobject("L\\left(%s\\right) = " % input_array_tex) matrix = Matrix( np.array([ ["x", "y", "z"], ["v_1", "v_2", "v_3"], ["w_1", "w_2", "w_3"], ]).T) matrix.highlight_columns(WHITE, U_COLOR, W_COLOR) det_text = get_det_text(matrix, background_rect=False) det_text.add(matrix) dot_with_cross = TexMobject("%s \\cdot ( " % input_array_tex, v_tex, "\\times", w_tex, ")") dot_with_cross.highlight_by_tex(v_tex, U_COLOR) dot_with_cross.highlight_by_tex(w_tex, W_COLOR) transform = Group(func, det_text) transform.arrange_submobjects() Group(transform, dot_with_cross).scale(0.7) Group(vector_word, cross).arrange_submobjects( RIGHT, buff=MED_BUFF).center().shift(LEFT).to_edge(UP) transform_word.next_to(vector_word, DOWN, buff=MED_BUFF, aligned_edge=LEFT) transform.next_to(transform_word, DOWN, buff=MED_BUFF, aligned_edge=LEFT) dot_with_cross.next_to(func, RIGHT) self.add(vector_word) self.play(Write(cross)) self.dither() self.play(FadeIn(transform_word)) self.play(Write(transform)) self.dither() self.play(Transform(det_text, dot_with_cross)) self.dither()
def show_triple_cross_product(self): colors = [WHITE, ORANGE, W_COLOR] tex_mobs = map(TexMobject, get_vect_tex(*"uvw")) u_tex, v_tex, w_tex = tex_mobs arrays = [ Matrix(["%s_%d" % (s, d) for d in range(1, 4)]) for s in "uvw" ] defs_equals = VGroup() definitions = VGroup() for array, tex_mob, color in zip(arrays, tex_mobs, colors): array.highlight_columns(color) tex_mob.highlight(color) equals = TexMobject("=") definition = VGroup(tex_mob, equals, array) definition.arrange_submobjects(RIGHT) definitions.add(definition) defs_equals.add(equals) definitions.arrange_submobjects(buff=MED_SMALL_BUFF) definitions.shift(2 * DOWN) mobs_with_targets = list( it.chain(tex_mobs, *[a.get_entries() for a in arrays])) for mob in mobs_with_targets: mob.target = mob.copy() matrix = Matrix( np.array([[e.target for e in array.get_entries()] for array in arrays]).T) det_text = get_det_text(matrix, background_rect=False) syms = times1, times2, equals = [ TexMobject(sym) for sym in "\\times", "\\times", "=", ] triple_cross = VGroup(u_tex.target, times1, v_tex.target, times2, w_tex.target, equals) triple_cross.arrange_submobjects() final_mobs = VGroup(triple_cross, VGroup(det_text, matrix)) final_mobs.arrange_submobjects() final_mobs.next_to(self.title, DOWN, buff=MED_SMALL_BUFF) for mob in definitions, final_mobs: mob.scale_to_fit_width(SPACE_WIDTH - 1) for array in arrays: brackets = array.get_brackets() brackets.target = matrix.get_brackets() mobs_with_targets.append(brackets) for def_equals in defs_equals: def_equals.target = equals mobs_with_targets.append(def_equals) self.play( FadeIn(definitions, run_time=2, submobject_mode="lagged_start")) self.dither(2) self.play(*[Transform(mob.copy(), mob.target) for mob in tex_mobs] + [ Write(times1), Write(times2), ]) triple_cross.add(*self.get_mobjects_from_last_animation()[:3]) self.play(*[ Transform(mob.copy(), mob.target) for mob in mobs_with_targets if mob not in tex_mobs ]) u_entries = self.get_mobjects_from_last_animation()[:3] v_entries = self.get_mobjects_from_last_animation()[3:6] w_entries = self.get_mobjects_from_last_animation()[6:9] self.play(Write(det_text)) self.dither(2) self.det_text = det_text self.definitions = definitions self.u_entries = u_entries self.v_entries = v_entries self.w_entries = w_entries self.matrix = matrix self.triple_cross = triple_cross self.v_tex, self.w_tex = v_tex, w_tex self.equals = equals
def show_triple_cross_product(self): colors = [WHITE, ORANGE, W_COLOR] tex_mobs = map(TexMobject, get_vect_tex(*"uvw")) u_tex, v_tex, w_tex = tex_mobs arrays = [ Matrix(["%s_%d"%(s, d) for d in range(1, 4)]) for s in "uvw" ] defs_equals = Group() definitions = Group() for array, tex_mob, color in zip(arrays, tex_mobs, colors): array.highlight_columns(color) tex_mob.highlight(color) equals = TexMobject("=") definition = Group(tex_mob, equals, array) definition.arrange_submobjects(RIGHT) definitions.add(definition) defs_equals.add(equals) definitions.arrange_submobjects(buff = MED_BUFF) definitions.shift(2*DOWN) mobs_with_targets = list(it.chain( tex_mobs, *[a.get_entries() for a in arrays] )) for mob in mobs_with_targets: mob.target = mob.copy() matrix = Matrix(np.array([ [e.target for e in array.get_entries()] for array in arrays ]).T) det_text = get_det_text(matrix, background_rect = False) syms = times1, times2, equals = [ TexMobject(sym) for sym in "\\times", "\\times", "=", ] triple_cross = Group( u_tex.target, times1, v_tex.target, times2, w_tex.target, equals ) triple_cross.arrange_submobjects() final_mobs = Group(triple_cross, Group(det_text, matrix)) final_mobs.arrange_submobjects() final_mobs.next_to(self.title, DOWN, buff = MED_BUFF) for mob in definitions, final_mobs: mob.scale_to_fit_width(SPACE_WIDTH - 1) for array in arrays: brackets = array.get_brackets() brackets.target = matrix.get_brackets() mobs_with_targets.append(brackets) for def_equals in defs_equals: def_equals.target = equals mobs_with_targets.append(def_equals) self.play(FadeIn( definitions, run_time = 2, submobject_mode = "lagged_start" )) self.dither(2) self.play(*[ Transform(mob.copy(), mob.target) for mob in tex_mobs ] + [ Write(times1), Write(times2), ]) triple_cross.add(*self.get_mobjects_from_last_animation()[:3]) self.play(*[ Transform(mob.copy(), mob.target) for mob in mobs_with_targets if mob not in tex_mobs ]) u_entries = self.get_mobjects_from_last_animation()[:3] v_entries = self.get_mobjects_from_last_animation()[3:6] w_entries = self.get_mobjects_from_last_animation()[6:9] self.play(Write(det_text)) self.dither(2) self.det_text = det_text self.definitions = definitions self.u_entries = u_entries self.v_entries = v_entries self.w_entries = w_entries self.matrix = matrix self.triple_cross = triple_cross self.v_tex, self.w_tex = v_tex, w_tex self.equals = equals
def construct(self): self.plane.fade() v = Vector(self.v_coords, color=V_COLOR) w = Vector(self.w_coords, color=W_COLOR) v.coords = Matrix(self.v_coords) w.coords = Matrix(self.w_coords) v.coords.next_to(v.get_end(), LEFT) w.coords.next_to(w.get_end(), RIGHT) v.coords.highlight(v.get_color()) w.coords.highlight(w.get_color()) for coords in v.coords, w.coords: coords.background_rectangle = BackgroundRectangle(coords) coords.add_to_back(coords.background_rectangle) v.label = self.get_vector_label(v, "v", "left", color=v.get_color()) w.label = self.get_vector_label(w, "w", "right", color=w.get_color()) matrix = Matrix( np.array([ list(v.coords.copy().get_entries()), list(w.coords.copy().get_entries()), ]).T) matrix_background = BackgroundRectangle(matrix) col1, col2 = it.starmap(Group, matrix.get_mob_matrix().T) det_text = get_det_text(matrix) v_tex, w_tex = get_vect_tex("v", "w") cross_product = TexMobject(v_tex, "\\times", w_tex, "=") cross_product.highlight_by_tex(v_tex, V_COLOR) cross_product.highlight_by_tex(w_tex, W_COLOR) cross_product.add_background_rectangle() equation_start = Group(cross_product, Group(matrix_background, det_text, matrix)) equation_start.arrange_submobjects() equation_start.next_to(ORIGIN, DOWN).to_edge(LEFT) for vect in v, w: self.play(ShowCreation(vect), Write(vect.coords), Write(vect.label)) self.dither() self.play( Transform(v.coords.background_rectangle, matrix_background), Transform(w.coords.background_rectangle, matrix_background), Transform(v.coords.get_entries(), col1), Transform(w.coords.get_entries(), col2), Transform(v.coords.get_brackets(), matrix.get_brackets()), Transform(w.coords.get_brackets(), matrix.get_brackets()), ) self.play(*map(Write, [det_text, cross_product])) v1, v2 = v.coords.get_entries() w1, w2 = w.coords.get_entries() entries = v1, v2, w1, w2 for entry in entries: entry.target = entry.copy() det = np.linalg.det([self.v_coords, self.w_coords]) equals, dot1, minus, dot2, equals_result = syms = Group( *map(TexMobject, ["=", "\\cdot", "-", "\\cdot", "=%d" % det])) equation_end = Group(equals, v1.target, dot1, w2.target, minus, w1.target, dot2, v2.target, equals_result) equation_end.arrange_submobjects() equation_end.next_to(equation_start) syms_rect = BackgroundRectangle(syms) syms.add_to_back(syms_rect) equation_end.add_to_back(syms_rect) syms.remove(equals_result) self.play(Write(syms), Transform(Group(v1, w2).copy(), Group(v1.target, w2.target), rate_func=squish_rate_func(smooth, 0, 1. / 3), path_arc=np.pi / 2), Transform(Group(v2, w1).copy(), Group(v2.target, w1.target), rate_func=squish_rate_func(smooth, 2. / 3, 1), path_arc=np.pi / 2), run_time=3) self.dither() self.play(Write(equals_result)) self.add_foreground_mobject(equation_start, equation_end) self.show_transformation(v, w) det_sym = TexMobject(str(int(abs(det)))) det_sym.scale(1.5) det_sym.next_to(v.get_end() + w.get_end(), DOWN + RIGHT, buff=MED_BUFF / 2) arc = self.get_arc(v, w, radius=1) arc.highlight(RED) self.play(Write(det_sym)) self.play(ShowCreation(arc)) self.dither()
def initial_definition(self): self.plane.save_state() self.plane.fade() v = self.add_vector(self.v_coords, color=V_COLOR) w = self.add_vector(self.w_coords, color=W_COLOR) self.moving_vectors.remove(v) self.moving_vectors.remove(w) for vect, name, direction in (v, "v", "left"), (w, "w", "right"): color = vect.get_color() vect.label = self.label_vector( vect, name, color=color, direction=direction, ) vect.coord_array = vector_coordinate_label( vect, color=color, ) vect.coords = vect.coord_array.get_entries() for vect, edge in (v, DOWN), (w, UP): vect.coord_array.move_to(vect.coord_array.get_center(), aligned_edge=edge) self.play(Write(vect.coord_array, run_time=1)) movers = [v.label, w.label, v.coords, w.coords] for mover in movers: mover.target = mover.copy() times = TexMobject("\\times") cross_product = Group(v.label.target, times, w.label.target) cross_product.arrange_submobjects() matrix = Matrix( np.array([list(v.coords.target), list(w.coords.target)]).T) det_text = get_det_text(matrix) full_det = Group(det_text, matrix) equals = TexMobject("=") equation = Group(cross_product, equals, full_det) equation.arrange_submobjects() equation.to_corner(UP + LEFT) matrix_background = BackgroundRectangle(matrix) cross_background = BackgroundRectangle(cross_product) disclaimer = TextMobject( "$^*$ See ``Note on conventions'' in description") disclaimer.scale(0.7) disclaimer.highlight(RED) disclaimer.next_to(det_text.get_corner(UP + RIGHT), RIGHT, buff=0) disclaimer.add_background_rectangle() self.play( FadeIn(cross_background), Transform(v.label.copy(), v.label.target), Transform(w.label.copy(), w.label.target), Write(times), ) self.dither() self.play(ShowCreation(matrix_background), Write(matrix.get_brackets()), run_time=1) self.play(Transform(v.coords.copy(), v.coords.target)) self.play(Transform(w.coords.copy(), w.coords.target)) matrix.add_to_back(matrix_background) self.dither() self.play( Write(equals), Write(det_text), Animation(matrix), ) self.dither() self.play(FadeIn(disclaimer)) self.dither() self.play(FadeOut(disclaimer)) self.dither() cross_product.add_to_back(cross_background) cross_product.add(equals) self.cross_product = cross_product self.matrix = matrix self.det_text = det_text self.v, self.w = v, w
def construct(self): v_terms, w_terms = [["%s_%d" % (s, d) for d in range(1, 4)] for s in "v", "w"] v = Matrix(v_terms) w = Matrix(w_terms) v.highlight(V_COLOR) w.highlight(W_COLOR) matrix = Matrix( np.array([ [ TexMobject("\\hat{%s}" % s) for s in "\\imath", "\\jmath", "k" ], list(v.get_entries().copy()), list(w.get_entries().copy()), ]).T) colors = [X_COLOR, Y_COLOR, Z_COLOR] col1, col2, col3 = it.starmap(Group, matrix.get_mob_matrix().T) i, j, k = col1 v1, v2, v3 = col2 w1, w2, w3 = col3 ##Really should fix Matrix mobject... j.shift(0.1 * UP) k.shift(0.2 * UP) Group(v2, w2).shift(0.1 * DOWN) Group(v3, w3).shift(0.2 * DOWN) ## for color, entry in zip(colors, col1): entry.highlight(color) det_text = get_det_text(matrix) equals = TexMobject("=") equation = Group(v, TexMobject("\\times"), w, equals, Group(det_text, matrix)) equation.arrange_submobjects() self.add(*equation[:-2]) self.dither() self.play(Write(matrix.get_brackets())) for col, vect in (col2, v), (col3, w): col.save_state() col.move_to(vect.get_entries()) self.play( col.restore, path_arc=-np.pi / 2, ) for entry in col1: self.play(Write(entry)) self.dither() self.play(*map(Write, [equals, det_text])) self.dither() disclaimer = TextMobject( "$^*$ See ``Note on conventions'' in description") disclaimer.scale(0.7) disclaimer.highlight(RED) disclaimer.next_to(equation, DOWN) self.play(FadeIn(disclaimer)) self.dither() self.play(FadeOut(disclaimer)) circle = Circle() circle.stretch_to_fit_height(col1.get_height() + 1) circle.stretch_to_fit_width(col1.get_width() + 1) circle.move_to(col1) randy = Randolph() randy.scale(0.9) randy.to_corner() randy.to_edge(DOWN, buff=SMALL_BUFF) self.play(FadeIn(randy)) self.play(randy.change_mode, "confused", ShowCreation(circle)) self.play(randy.look, RIGHT) self.dither() self.play(FadeOut(circle)) self.play( equation.to_corner, UP + LEFT, ApplyFunction(lambda r: r.change_mode("plain").look(UP + RIGHT), randy)) quints = [ (i, v2, w3, v3, w2), (j, v3, w1, v1, w3), (k, v1, w2, v2, w1), ] last_mob = None paren_sets = [] for quint in quints: for mob in quint: mob.t = mob.copy() mob.save_state() basis = quint[0] basis.t.scale(1 / 0.8) lp, minus, rp = syms = Group(*map(TexMobject, "(-)")) term = Group(basis.t, lp, quint[1].t, quint[2].t, minus, quint[3].t, quint[4].t, rp) term.arrange_submobjects() if last_mob: plus = TexMobject("+") syms.add(plus) plus.next_to(term, LEFT, buff=MED_BUFF / 2) term.add_to_back(plus) term.next_to(last_mob, RIGHT, buff=MED_BUFF / 2) else: term.next_to(equation, DOWN, buff=MED_BUFF, aligned_edge=LEFT) last_mob = term self.play(*it.chain(*[[mob.scale_in_place, 1.2] for mob in quint])) self.dither() self.play(*[Transform(mob.copy(), mob.t) for mob in quint] + [mob.restore for mob in quint] + [Write(syms)], run_time=2) self.dither() paren_sets.append(Group(lp, rp)) self.dither() self.play(randy.change_mode, "pondering") for parens in paren_sets: brace = Brace(parens) text = brace.get_text("Some number") text.scale_to_fit_width(brace.get_width()) self.play(GrowFromCenter(brace), Write(text, run_time=2)) self.dither()