コード例 #1
0
ファイル: prop2.py プロジェクト: codecxx/manim_sandbox
 def construct(self):
     sub1 = CText('这将是一个')
     sub2 = CText('关于线段长度的性质')
     subs = VGroup(sub1, sub2)
     subs.arrange(DOWN)
     self.play(Write(sub1))
     self.play(Write(sub2))
     self.wait(2)
     self.play(FadeOut(subs))
コード例 #2
0
    def construct(self):
        text1 = CText('这是一条重要的性质')
        text2 = CText('后面会经常用到')

        group = VGroup(text1, text2)
        group.arrange(DOWN)

        self.play(Write(text1))
        self.wait()
        self.play(Write(text2))
        self.wait()
        self.play(FadeOut(group))
コード例 #3
0
    def construct(self):
        sub1 = CText('根据性质1')
        sub2 = CText('可以用另一种方法找到')
        sub3 = CText('抛物线上的点')

        subs = VGroup(sub1, sub2, sub3)
        subs.arrange(DOWN)

        self.play(Write(sub1))
        self.wait()
        self.play(Write(sub2))
        self.wait()
        self.play(Write(sub3))
        self.wait(5)
        self.play(FadeOut(subs))
コード例 #4
0
    def construct(self):
        text = CText('总结')
        text.set_fill(DARK_BROWN)

        content1 = CText('抛物线任意弦与准线的交点')
        content2 = CText('及该抛物线的焦点所构成的线段,')
        content3 = CText('平分该弦两端点与焦点所构成角的外角')
        contents = VGroup(content1, content2, content3)
        contents.scale(0.7)
        contents.arrange(DOWN)

        total = VGroup(text, contents)
        total.arrange(DOWN, buff=MED_LARGE_BUFF)

        self.play(Write(text))
        self.wait(2)
        self.play(Write(contents))
        self.wait(10)
コード例 #5
0
ファイル: prop3_probs.py プロジェクト: codecxx/manim_sandbox
    def construct(self):
        line1_1 = CText('抛物线')
        line1_1.set_fill(DARK_BLUE)

        line1_2 = CText('性质三')
        line1 = VGroup(line1_1, line1_2)
        line1.arrange(RIGHT)
        line2 = CText('推论一')
        lines = VGroup(line1, line2)
        lines.arrange(DOWN, buff=LARGE_BUFF)
        self.play(Write(line1))
        self.wait(3)
        self.play(Write(line2))
        self.wait(3)

        self.play(FadeOut(lines))
コード例 #6
0
ファイル: prop2.py プロジェクト: codecxx/manim_sandbox
    def construct(self):
        text = CText('总结')
        text.set_fill(DARK_BROWN)

        content1 = CText('纵标线的平方等于')
        content2 = CText('横标线与焦距乘积的四倍')
        contents = VGroup(content1, content2)
        contents.scale(0.7)
        contents.arrange(DOWN)

        total = VGroup(text, contents)
        total.arrange(DOWN, buff=MED_LARGE_BUFF)

        self.play(Write(text))
        self.wait(2)
        self.play(Write(contents))
        self.wait(10)
コード例 #7
0
ファイル: prop3_probs.py プロジェクト: codecxx/manim_sandbox
    def construct(self):
        self.adjust_x_range()
        graph = self.get_graph(color=LIGHT_BROWN)
        directrix = self.get_directrix()
        focus = Dot().move_to(self.get_focus())
        focus.set_fill(DARK_BROWN)
        focus.plot_depth = 2
        focusLabel = TexMobject('F').scale(0.5)
        focusLabel.next_to(focus, RIGHT, buff=SMALL_BUFF)

        self.play(*[ShowCreation(e) for\
            e in [graph, directrix, focus, focusLabel]])
        self.wait()

        sub1 = CText('任取一点P').scale(0.3)
        sub1.to_edge(RIGHT)
        self.play(ShowCreation(sub1))

        y_val = ValueTracker(6)

        p = Dot()
        p.plot_depth = 1
        p.set_fill(DARK_BLUE)
        p.add_updater(lambda m:\
            m.move_to(self.coords_to_point(
                self.func(y_val.get_value()),
                y_val.get_value()
            )))

        self.play(ShowCreation(p))

        p_label = TexMobject('P').scale(0.5)
        p_label.plot_depth = 1
        p_label.add_updater(lambda m:\
            m.next_to(p, RIGHT, buff=SMALL_BUFF))
        self.play(ShowCreation(p_label))
        self.wait()

        self.play(FadeOut(sub1))

        sub2 = CText('过点P做抛物线的切线')
        sub2.scale(0.3)
        sub2.to_edge(RIGHT)
        self.play(ShowCreation(sub2))
        self.wait()

        tangent = Line()
        self.add_tangent_line_updater(tangent, p)
        # self.play(ShowCreation(tangent))
        # self.wait()

        tangent_extent = Line()

        def get_extent(l, p, t):
            l.put_start_and_end_on(LEFT * 10, RIGHT * 10)
            l.set_angle(t.get_angle() + PI)
            l.move_to(p.get_center())
        tangent_extent.add_updater(lambda l:\
            get_extent(l, p, tangent))
        tangent_line = VGroup()
        tangent_line.add(tangent)
        tangent_line.add(tangent_extent)
        self.play(ShowCreation(tangent_extent))
        self.add(tangent_line)

        self.wait()

        self.play(FadeOut(sub2))

        sub3 = CText('交准线于Z').scale(0.3)
        sub3.to_edge(RIGHT)
        self.play(ShowCreation(sub3))
        self.wait()

        z = Dot()
        z.plot_depth = 1
        z.set_fill(DARK_BLUE)
        z.add_updater(lambda m:\
            m.move_to(self.get_tangent_to_directrix(p)))
        self.play(ShowCreation(z))

        z_label = TexMobject('Z').scale(0.5)
        z_label.plot_depth = 1
        z_label.add_updater(lambda m:\
            m.next_to(z, LEFT, buff=SMALL_BUFF))
        self.play(ShowCreation(z_label))
        self.wait()

        self.play(FadeOut(sub3))
        sub4 = CText('交正焦弦于点K').scale(0.3)
        sub4.to_edge(RIGHT)
        self.play(ShowCreation(sub4))
        self.wait()

        def find_k():
            start = z.get_center()
            vec = p.get_center() - start
            vec /= vec[0]
            d = focus.get_center()[0] - start[0]
            vec *= d
            return start + vec

        k = Dot()
        k.plot_depth = 1
        k.set_fill(DARK_BLUE)
        k.add_updater(lambda m:\
            m.move_to(find_k()))

        k_label = TexMobject('K').scale(0.5)
        k_label.plot_depth = 1
        k_label.add_updater(lambda m:\
            m.next_to(k, RIGHT, buff=SMALL_BUFF))

        def find_opp():
            pos = find_k()
            fac = -1
            if pos[1] < 0:
                fac = 1
            return self.coords_to_point(self.func(self.focus * 2),
                                        fac * self.focus * 2)

        k_line = Line()
        k_line.add_updater(lambda m:\
            m.put_start_and_end_on(
                find_k(),
                find_opp()
            ))

        self.play(ShowCreation(k_line))
        self.play(ShowCreation(k))
        self.play(ShowCreation(k_label))

        self.wait()

        self.play(FadeOut(sub4))
        sub5 = CText('则ZF=KF').scale(0.3)
        sub5.to_edge(RIGHT)
        self.play(ShowCreation(sub5))
        self.wait()

        zf = Line()
        zf.set_color(RED)
        zf.add_updater(lambda m:\
            m.put_start_and_end_on(
                z.get_center(),
                focus.get_center()
            ))
        kf = Line()
        kf.set_color(RED)
        kf.add_updater(lambda m:\
            m.put_start_and_end_on(
                k.get_center(),
                focus.get_center()
            ))
        self.play(ShowCreation(zf), ShowCreation(kf))
        self.wait()

        self.play(y_val.set_value, 9, rate_func=easeOutElastic, run_time=2)
        self.wait()

        self.play(y_val.set_value, 1, rate_func=easeOutBounce, run_time=2)
        self.wait()

        self.play(y_val.set_value, -6, rate_func=easeOutElastic, run_time=2)
        self.wait()

        self.play(y_val.set_value, 8, rate_func=easeOutBounce, run_time=2)
        self.wait()

        self.play(FadeOut(sub5))

        m = Dot()
        m.plot_depth = 1
        m.set_fill(YELLOW)
        m.add_updater(lambda e:\
            e.move_to(z.get_center()[0] * RIGHT +
                p.get_center()[1] * UP))

        m_label = TexMobject('M').scale(0.5)
        m_label.add_updater(lambda e:\
            e.next_to(m, LEFT, buff=SMALL_BUFF))

        self.play(ShowCreation(m))
        self.play(ShowCreation(m_label))

        mp = DashedLine()
        mp.add_updater(lambda l:\
            l.put_start_and_end_on(
                m.get_center(),
                p.get_center()
            ))
        self.play(ShowCreation(mp))

        fp = DashedLine()
        fp.add_updater(lambda l:\
            l.put_start_and_end_on(
                focus.get_center(),
                p.get_center()
            ))
        self.play(ShowCreation(fp))
        self.wait()

        km = DashedLine()
        km.add_updater(lambda l:\
            l.put_start_and_end_on(
                k.get_center(),
                m.get_center()
            ))
        self.play(ShowCreation(km))

        k2 = Dot()
        k2.plot_depth = 1
        k2.set_fill(YELLOW)
        k2.add_updater(lambda m:\
            m.move_to(
                k.get_center()[1] * UP +
                z.get_center()[0] * RIGHT
            ))
        self.play(ShowCreation(k2))

        k2_label = TexMobject('K\'').scale(0.5)
        k2_label.add_updater(lambda m:\
            m.next_to(k2, LEFT, buff=SMALL_BUFF))
        self.play(ShowCreation(k2_label))

        kk2 = DashedLine()
        kk2.add_updater(lambda l:\
            l.put_start_and_end_on(
                k.get_center(),
                k2.get_center()
            ))
        self.play(ShowCreation(kk2))

        z2 = Dot()
        z2.plot_depth = 1
        z2.set_fill(YELLOW)
        z2.add_updater(lambda m:\
            m.move_to(
                z.get_center()[1] * UP +
                focus.get_center()[0] * RIGHT
            ))
        self.play(ShowCreation(z2))

        z2f = Line()
        z2f.plot_depth = -1
        z2f.add_updater(lambda l:\
            l.put_start_and_end_on(
                z2.get_center(),
                focus.get_center()
            ))
        self.add(z2f)

        z2_label = TexMobject('Z\'').scale(0.5)
        z2_label.add_updater(lambda m:\
            m.next_to(z2, UR, buff=SMALL_BUFF))
        self.play(ShowCreation(z2_label))

        zz2 = DashedLine()
        zz2.add_updater(lambda l:\
            l.put_start_and_end_on(
                z.get_center(),
                z2.get_center()
            ))
        self.play(ShowCreation(zz2))
        self.wait()

        self.play(kk2.set_color, RED)
        self.play(zz2.set_color, RED)

        proof = VGroup()
        proof1 = CText('证明思路').scale(0.3)
        proof2 = TexMobject('KK\'=ZZ\'').scale(0.5)
        proof3 = TexMobject('\\triangle ZKM \\cong \\triangle ZKF')
        proof3.scale(0.5)
        proof.add(proof1)
        proof.add(proof2)
        proof.add(proof3)
        proof.arrange(DOWN)
        proof.to_edge(RIGHT, buff=LARGE_BUFF)
        proof2.align_to(proof1, LEFT)
        proof3.align_to(proof2, LEFT)
        self.play(ShowCreation(proof))
        self.wait(5)

        zkm = Polygon(z.get_center(), k.get_center(), m.get_center())
        zkm.set_fill(DARK_BLUE, opacity=0.5)

        zkf = Polygon(z.get_center(), k.get_center(), focus.get_center())
        zkf.set_fill(DARK_BLUE, opacity=0.5)

        self.play(ShowCreationThenDestruction(zkm),
                  ShowCreationThenDestruction(zkf))
        self.wait(15)

        self.play(y_val.set_value, 1, rate_func=easeOutBounce)
        self.wait(5)

        self.play(y_val.set_value, -1, rate_func=easeOutElastic)
        self.wait(5)

        self.play(y_val.set_value, -8, rate_func=easeOutBounce)
        self.wait(5)
コード例 #8
0
ファイル: prop3_probs.py プロジェクト: codecxx/manim_sandbox
    def construct(self):
        self.adjust_x_range()
        graph = self.get_graph(color=LIGHT_BROWN)
        directrix = self.get_directrix()
        focus = Dot().move_to(self.get_focus())
        focus.set_fill(DARK_BROWN)
        focus.plot_depth = 1
        focusLabel = TexMobject('F').scale(0.5)
        focusLabel.next_to(focus, RIGHT, buff=SMALL_BUFF)

        self.play(*[ShowCreation(e) for\
            e in [graph, directrix, focus, focusLabel]])

        sub1 = CText('P1P2为抛物线正焦弦').scale(0.3)
        sub1.to_edge(RIGHT)

        self.wait(2)
        self.play(Write(sub1))

        p1 = Dot()
        p1.move_to(self.coords_to_point(self.focus, 2 * self.focus))
        p1.plot_depth = 1
        p1.set_fill(DARK_BROWN)

        p2 = Dot()
        p2.move_to(self.coords_to_point(self.focus, -2 * self.focus))
        p2.plot_depth = 1
        p2.set_fill(DARK_BROWN)

        p1_label = TexMobject('P_1').scale(0.5)
        p1_label.next_to(p1, RIGHT)

        p2_label = TexMobject('P_2').scale(0.5)
        p2_label.next_to(p2, RIGHT)

        self.play(ShowCreation(p1), ShowCreation(p2))
        self.play(ShowCreation(Line(p1, p2)))
        self.play(ShowCreation(p1_label), ShowCreation(p2_label))
        self.wait()

        x = Dot()
        x.move_to(self.coords_to_point(-self.focus, 0))
        x.set_fill(DARK_BROWN)
        x.plot_depth = 1

        x_label = TexMobject('X').scale(0.5)
        x_label.next_to(x, LEFT)

        sub2 = CText('X为轴与准线的交点').scale(0.3)
        sub2.to_edge(RIGHT)

        self.play(FadeOut(sub1))
        self.play(FadeIn((sub2)))
        self.wait()

        h_line = Line(focus, x)
        h_line.plot_depth = 2

        self.play(ShowCreation(h_line))
        self.play(ShowCreation(x))
        self.play(FadeOut(h_line))
        self.play(Write(x_label))
        self.wait()

        sub3 = CText('则P1与P2的切线交于X').scale(0.3)
        sub3.to_edge(RIGHT)

        self.play(FadeOut(sub2))
        self.play(Write(sub3))

        p1_tangent = Line()
        self.add_tangent_line_updater(p1_tangent, p1)

        p2_tangent = Line()
        self.add_tangent_line_updater(p2_tangent, p2)

        self.play(ShowCreation(p1_tangent), ShowCreation(p2_tangent))

        self.wait()

        self.play(ShowCreation(DashedLine(x, focus)))

        m1 = Dot()
        m1.move_to(self.coords_to_point(-self.focus, 2 * self.focus))
        m1.set_fill(DARK_BROWN)
        m1.plot_depth = 1

        m1_label = TexMobject('M_1').scale(0.5)
        m1_label.next_to(m1, LEFT)

        self.play(ShowCreation(m1))
        self.play(ShowCreation(m1_label))
        self.play(ShowCreation(DashedLine(p1, m1)))

        sub4 = CText('在正方形XFP1M1中,XP1是对角线')
        sub4.scale(0.3)
        sub4.to_edge(RIGHT)
        self.play(FadeOut(sub3))
        self.play(Write(sub4))

        self.wait(5)
        self.play(
            ShowCreationThenDestruction(
                Polygon(x.get_center(), focus.get_center(), p1.get_center(),
                        m1.get_center())))

        sub5 = CText('XP1也正好平分角M1P1F,因此是过P1点的切线')
        sub5.scale(0.3)
        sub5.to_edge(RIGHT)

        self.wait(5)
        self.play(FadeOut(sub4))
        self.play(Write(sub5))

        sub6 = CText('同理,P2X也为切线')
        sub6.scale(0.3)
        sub6.to_edge(RIGHT)

        self.wait(5)
        self.play(FadeOut(sub5))
        self.play(Write(sub6))

        sub7 = CText('总结:抛物线正焦弦端点切线交于准线与轴的交点')
        sub7.scale(0.3)
        sub7.to_edge(RIGHT)

        self.wait(5)
        self.play(FadeOut(sub6))
        self.play(Write(sub7))

        self.wait(10)
コード例 #9
0
ファイル: prop3_probs.py プロジェクト: codecxx/manim_sandbox
    def construct(self):
        self.adjust_x_range()
        graph = self.get_graph(color=LIGHT_BROWN)
        directrix = self.get_directrix()
        focus = Dot().move_to(self.get_focus())
        focus.set_fill(DARK_BROWN)
        focus.plot_depth = 1
        focusLabel = TexMobject('F').scale(0.5)
        focusLabel.next_to(focus, RIGHT, buff=SMALL_BUFF)

        self.play(*[ShowCreation(e) for\
            e in [graph, directrix, focus, focusLabel]])

        y_val = ValueTracker(8)

        p = Dot()
        p.plot_depth = 1
        p.set_fill(DARK_BLUE)
        p.add_updater(lambda m:\
            m.move_to(self.coords_to_point(
                self.func(y_val.get_value()),
                y_val.get_value()
            )))

        p_label = TexMobject('P').scale(0.5)
        p_label.plot_depth = 1
        p_label.add_updater(lambda m:\
            m.next_to(p, RIGHT, buff=SMALL_BUFF))

        k = Dot()
        k.plot_depth = 1
        k.set_fill(DARK_BLUE)
        k.add_updater(lambda m:\
            m.move_to(self.get_tangent_to_directrix(
                p
            )))

        k_label = TexMobject('K').scale(0.5)
        k_label.plot_depth = 1
        k_label.add_updater(lambda m:\
            m.next_to(k, LEFT, buff=SMALL_BUFF))

        tangent = Line()
        self.add_tangent_line_updater(tangent, p)

        self.play(ShowCreation(p))
        self.play(ShowCreation(p_label))
        self.play(ShowCreation(tangent))
        self.play(ShowCreation(k))
        self.play(ShowCreation(k_label))

        def get_extent(l):
            l.put_start_and_end_on(p.get_center(), RIGHT * 10)
            l.set_angle(tangent.get_angle() + PI)

        tangent_extent = Line()
        tangent_extent.add_updater(lambda l:\
            get_extent(l))

        self.play(ShowCreation(tangent_extent))
        self.wait()

        m = Dot()
        m.set_fill(DARK_BLUE)
        m.plot_depth = 1
        m.add_updater(lambda e:\
            e.move_to(self.coords_to_point(
                -self.focus,
                y_val.get_value()
            )))

        m_label = TexMobject('M').scale(0.5)
        m_label.add_updater(lambda e:\
            e.next_to(m, LEFT, buff=SMALL_BUFF))

        mp = Line()
        mp.add_updater(lambda l:\
            l.put_start_and_end_on(
                p.get_center(),
                self.coords_to_point(
                    -self.focus,
                    y_val.get_value()
            )))

        fp = Line()
        fp.add_updater(lambda l:\
            l.put_start_and_end_on(
                focus.get_center(),
                p.get_center()
            ))

        self.play(ShowCreation(mp), ShowCreation(fp))
        self.play(ShowCreation(m))
        self.play(ShowCreation(m_label))

        kf = Line()
        kf.add_updater(lambda l:\
            l.put_start_and_end_on(
                k.get_center(),
                focus.get_center()
            ))
        self.play(ShowCreation(kf))
        self.wait()

        sub1 = CText('在切线上任取一点O')
        sub1.scale(0.3)
        sub1.to_edge(RIGHT)

        self.play(Write(sub1))
        self.wait()

        ot = ValueTracker(0.2)
        vec_kp = p.get_center() - k.get_center()

        o = Dot()
        o.plot_depth = 1
        o.set_fill(RED)
        o.add_updater(lambda m:\
            m.move_to(k.get_center() +\
                vec_kp * ot.get_value()))

        o_label = TexMobject('O').scale(0.5)
        o_label.plot_depth = 1
        o_label.add_updater(lambda m:\
            m.next_to(o, DR, buff=SMALL_BUFF))

        self.play(ShowCreation(o))
        self.play(ShowCreation(o_label))
        self.wait()

        sub2 = CText('则OM=OF')
        sub2.scale(0.3)
        sub2.to_edge(RIGHT)

        self.play(FadeOut(sub1))
        self.play(Write(sub2))
        self.wait()

        om = Line()
        om.add_updater(lambda l:\
            l.put_start_and_end_on(
                o.get_center(),
                m.get_center()
            ))
        of = Line()
        of.add_updater(lambda l:\
            l.put_start_and_end_on(
                o.get_center(),
                focus.get_center()
            ))

        self.play(ShowCreation(om), ShowCreation(of))
        self.wait()

        self.play(ot.set_value, 0.05)
        self.wait()
        self.play(ot.set_value, 0.8)
        self.wait()
        self.play(ot.set_value, 1.2)
        self.wait()
        self.play(ot.set_value, 0.6)
        self.wait(3)
コード例 #10
0
    def construct(self):
        self.adjust_x_range()
        graph = self.get_graph(color=LIGHT_BROWN)
        focus = Dot().move_to(self.get_focus())
        focus.set_fill(DARK_BROWN)
        focus.plot_depth = 1
        focusLabel = TexMobject('F').scale(0.5)
        focusLabel.next_to(focus, DOWN, buff=SMALL_BUFF)
        focusLabel.plot_depth = 1

        self.play(*[ShowCreation(e) for\
            e in [graph, focus, focusLabel]])

        h_line = Line(self.coords_to_point(0, 0), ORIGIN)
        h_line.plot_depth = -1
        self.play(ShowCreation(h_line))

        a = Dot()
        a.move_to(self.coords_to_point(0, 0))
        a.plot_depth = 1
        a.set_fill(DARK_BROWN)
        a_label = TexMobject('A').scale(0.5)
        a_label.next_to(a, DL, buff=SMALL_BUFF)
        a_label.plot_depth = 1

        self.play(
            ShowCreation(a),
            Write(a_label)
        )
        self.wait()

        y_val = ValueTracker(6.5)

        p1 = Dot()
        p1.set_fill(DARK_BLUE)
        p1.plot_depth = 1
        p1.add_updater(lambda m:\
            m.move_to(self.coords_to_point(
                self.func(y_val.get_value()),
                y_val.get_value()
            )))
        p1_label = TexMobject('P_1').scale(0.5)
        p1_label.plot_depth = 1
        p1_label.add_updater(lambda m:\
            m.next_to(p1, RIGHT, buff=SMALL_BUFF))

        p2 = Dot()
        p2.set_fill(DARK_BLUE)
        p2.plot_depth = 1
        p2.add_updater(lambda m:\
            m.move_to(self.coords_to_point(
                self.func(-y_val.get_value()),
                -y_val.get_value()
            )))
        p2_label = TexMobject('P_2').scale(0.5)
        p2_label.plot_depth = 1
        p2_label.add_updater(lambda m:\
            m.next_to(p2, RIGHT, buff=SMALL_BUFF))

        p1p2 = Line()
        p1p2.add_updater(lambda m:\
            m.put_start_and_end_on(
                self.coords_to_point(
                    self.func(y_val.get_value()),
                    y_val.get_value()
                ),
                self.coords_to_point(
                    self.func(-y_val.get_value()),
                    -y_val.get_value()
            )))
        self.play(
            ShowCreation(p1),
            Write(p1_label)
        )
        self.play(ShowCreation(p1p2))
        self.play(
            ShowCreation(p2),
            Write(p2_label)
        )
        self.wait()

        n1 = Dot()
        n1.set_fill(DARK_BLUE)
        n1.plot_depth = 1
        n1.add_updater(lambda m:\
            m.move_to(p1.get_center()[0] * RIGHT))
        n1_label = TexMobject('N').scale(0.5)
        n1_label.add_updater(lambda m:\
            m.next_to(n1, DR, buff=SMALL_BUFF))
        self.play(
            ShowCreation(n1),
            Write(n1_label)
        )
        self.wait()

        q_y = ValueTracker(5)

        q = Dot()
        q.set_fill(DARK_BLUE)
        q.plot_depth = 1
        q.add_updater(lambda m:\
            m.move_to(self.coords_to_point(
                self.func(q_y.get_value()),
                q_y.get_value()
            )))
        q_label = TexMobject('Q').scale(0.5)
        q_label.plot_depth = 1
        q_label.add_updater(lambda m:\
            m.next_to(q, LEFT, buff=SMALL_BUFF))
        self.play(
            ShowCreation(q),
            Write(q_label)
        )

        self.wait()

        def get_l():
            qy = q_y.get_value()
            qx = self.func(qy)
            py = y_val.get_value()
            px = self.func(py)

            l = qy / qx * px
            return self.coords_to_point(px, l)

        l = Dot()
        l.set_fill(DARK_BLUE)
        l.plot_depth = 1
        l.add_updater(lambda m:\
            m.move_to(get_l()))
        l_label = TexMobject('L').scale(0.5)
        l_label.add_updater(lambda m:\
            m.next_to(l, RIGHT, buff=SMALL_BUFF))

        al = Line()
        al.add_updater(lambda m:\
            m.put_start_and_end_on(
                a.get_center(),
                get_l() if\
                    q_y.get_value() < y_val.get_value()\
                    else q.get_center()
            ))
        p1l = Line()
        p1l.add_updater(lambda m:\
            m.put_start_and_end_on(
                p1.get_center(),
                get_l()
            ))
        self.play(
            ShowCreation(al),
            ShowCreation(p1l))
        self.play(
            ShowCreation(l),
            Write(l_label)
        )

        self.wait()

        def get_l2():
            qy = q.get_center()[1]
            px = p1.get_center()[0]

            return px * RIGHT + qy * UP
        
        l2 = Dot()
        l2.set_fill(DARK_BLUE)
        l2.plot_depth = 1
        l2.add_updater(lambda m:\
            m.move_to(get_l2()))
        l2_label = TexMobject("L'").scale(0.5)
        l2_label.add_updater(lambda m:\
            m.next_to(l2, RIGHT, buff=SMALL_BUFF))
        
        ql2 = Line()
        ql2.add_updater(lambda m:\
            m.put_start_and_end_on(
                q.get_center(),
                get_l2()
            ))
        p1l2 = Line()
        p1l2.add_updater(lambda m:\
            m.put_start_and_end_on(
                p1.get_center(),
                get_l2()
            ))
        self.play(
            ShowCreation(ql2),
            ShowCreation(p1l2))
        self.play(
            ShowCreation(l2),
            Write(l2_label)
        )

        corollary = VGroup()

        head = CText('推论:').scale(0.25)
        head.set_fill(DARK_BLUE)
        
        crlly = TexMobject("P_1N^2=LN\\cdot L'N").scale(0.5)

        head_line = VGroup(head, crlly)
        head_line.arrange(RIGHT)

        proof = VGroup()
        proof_head = CText('证明:').scale(0.25)
        proof_head.set_fill(DARK_BLUE)
        proof.add(proof_head)

        proof_details = VGroup()
        prf1 = TexMobject("\\frac{LN}{AN}=\\frac{QN'}{AN'}")\
            .scale(0.5)

        prf2 = VGroup()
        prf2_1 = CText('又').scale(0.25)
        prf2_2 = TexMobject(
            "\\because L'N=QN'")\
            .scale(0.5)
        prf2.add(prf2_1, prf2_2)
        prf2.arrange(RIGHT, buff=SMALL_BUFF)

        prf3 = TexMobject(
            "\\therefore LN\\cdot L'N=\\frac{QN'\
                \\cdot AN}{AN'}\\cdot QN' =\
                \\frac{QN'^2\\cdot AN}{AN'}"
        ).scale(0.5)

        prf4 = VGroup()
        prf4_1 = CText('又').scale(0.25)
        prf4_2 = TexMobject(
            "\\because QN'^2=4AN'\\cdot AF")\
            .scale(0.5)
        prf4.add(prf4_1, prf4_2)
        prf4.arrange(RIGHT, buff=SMALL_BUFF)

        prf5 = TexMobject(
            "\\therefore LN\\cdot L'N=\\frac{4AN'\\cdot AF\
                \\cdot AN}{AN'} = 4AN\\cdot AF = P_1N^2"
        ).scale(0.5)

        proof_details.add(prf1, prf2, prf3,
            prf4, prf5)
        proof_details.arrange(DOWN)
        proof.add(proof_details)
        proof.arrange(RIGHT)
        proof_details.align_to(proof_head, UP)

        corollary.add(head_line)
        corollary.add(proof)
        corollary.arrange(DOWN)

        head_line.align_to(proof, LEFT)
        prf1.align_to(crlly, LEFT)
        for e in [prf2, prf3, prf4, prf5]:
            e.align_to(prf1, LEFT)

        corollary.to_edge(RIGHT)

        self.play(Write(head_line))
        self.wait()

        def get_n2():
            qx = q.get_center()[0]
            return qx * RIGHT

        n2 = Dot()
        n2.plot_depth = 1
        n2.set_fill(DARK_BLUE)
        n2.add_updater(lambda m:\
            m.move_to(get_n2()))

        n2_label = TexMobject("N'").scale(0.5)
        n2_label.add_updater(lambda m:\
            m.next_to(n2, DOWN, buff=SMALL_BUFF))
        
        qn2 = DashedLine()
        qn2.add_updater(lambda m:\
            m.put_start_and_end_on(
                q.get_center(),
                get_n2()
            ))
        self.play(ShowCreation(qn2))
        self.play(
            ShowCreation(n2),
            Write(n2_label)
        )
        self.wait()

        self.play(
            Write(proof_head),
            Write(prf1))
        self.wait(3)

        self.play(ShowCreationThenDestruction(
            Polygon(
                a.get_center(),
                n2.get_center(),
                q.get_center())
        ))
        self.wait()

        self.play(ShowCreationThenDestruction(
            Polygon(
                a.get_center(),
                n1.get_center(),
                l.get_center())
        ))

        for e in [prf2, prf3, prf4, prf5]:
            self.wait(3)
            self.play(Write(e))

        self.wait(10)

        self.play(y_val.set_value, 4)
        self.play(q_y.set_value, 8)

        self.wait(10)
コード例 #11
0
    def construct(self):
        text1head = CText('高中时期的解析几何都用')
        text1body = CText('坐标系')
        text1tail = CText('进行研究')
        text1 = VGroup(text1head, text1body, text1tail, buff=SMALL_BUFF)
        text1.arrange()
        text1body.set_fill(DARK_BLUE)

        text2 = CText('计算繁杂,且不优雅')

        text3head = CText('那么,是否可以用')
        text3body = CText('纯几何')
        text3tail = CText('的方法')
        text3 = VGroup(text3head, text3body, text3tail, buff=SMALL_BUFF)
        text3body.set_fill(DARK_BLUE)
        text3.arrange()

        # text2[1].set_fill(DARK_BLUE)
        text4 = CText('来得到一些圆锥曲线的性质?')

        group = VGroup(text1, text2, text3, text4)
        group.arrange_submobjects(direction=DOWN, buff=1)
        group.scale(0.5)
        self.play(Write(text1))
        self.play(WiggleOutThenIn(text1body))
        self.wait()
        self.play(Write(text2))
        self.wait()
        self.play(Write(text3))
        self.play(WiggleOutThenIn(text3body))
        self.wait()
        self.play(Write(text4))
        self.wait(2)

        self.play(FadeOut(group))

        explan1 = CText('本系列将试图用几何方法研究圆锥曲线')
        explan2h = CText('主要参考')
        explan2t = CText('《圆锥曲线的几何性质》')
        explan2 = VGroup(explan2h, explan2t)
        explan2.arrange()
        explan2t.set_fill(DARK_BLUE)

        explan3 = CText('希望能有所帮助')

        explan = VGroup(explan1, explan2, explan3)
        explan.arrange_submobjects(direction=DOWN, buff=1)
        explan.scale(0.5)

        self.play(Write(explan1))
        self.wait()
        self.play(Write(explan2))
        self.play(WiggleOutThenIn(explan2t))
        self.wait()
        self.play(Write(explan3))
        self.wait(2)
        self.play(FadeOut(explan))

        jokeh = CText('视频使用')
        jokeb = CText('manim')
        joket = CText('制作')

        jokeb.set_fill(DARK_BLUE)

        joked = CText('边学边做,随缘更新')
        jokeT = VGroup(jokeh, jokeb, joket, buff=SMALL_BUFF)
        jokeT.arrange()

        joke = VGroup(jokeT, joked)
        joke.arrange_submobjects(direction=DOWN, buff=1)

        self.play(Write(jokeT))
        self.play(WiggleOutThenIn(jokeb))
        self.wait()
        self.play(Write(joked))
        self.wait(2)
        self.play(FadeOut(joke))

        last = CText('从抛物线开始')
        self.play(Write(last))
        self.wait()
        self.play(FadeOut(last))
コード例 #12
0
    def construct(self):
        self.adjust_x_range()
        graph = self.get_graph(color=LIGHT_BROWN)
        directrix = self.get_directrix()
        focus = Dot().move_to(self.get_focus())
        focus.set_fill(DARK_BROWN)
        focus.plot_depth = 1
        focusLabel = TexMobject('F').scale(0.7)
        focusLabel.next_to(focus, RIGHT)

        self.play(*[ShowCreation(e) for\
            e in [graph, directrix, focus, focusLabel]])

        q1_y = ValueTracker(9)
        q1 = Dot()
        q1.set_fill(DARK_BLUE)
        q1.plot_depth = 1

        q1.add_updater(lambda m:\
            m.move_to(self.coords_to_point(
                self.func(q1_y.get_value()),
                q1_y.get_value()
            )))

        q1_label = TexMobject('Q_1').scale(0.5)
        q1_label.add_updater(lambda m:\
            m.next_to(q1, RIGHT, buff=SMALL_BUFF))
        
        self.play(ShowCreation(q1), ShowCreation(q1_label))

        q2 = Dot()
        q2.set_fill(DARK_BLUE)
        q2.plot_depth = 1

        q2.add_updater(lambda m:\
            m.move_to(self.get_opposite(q1)))

        q2_label = TexMobject('Q_2').scale(0.5)
        q2_label.add_updater(lambda m:\
            m.next_to(q2, RIGHT, buff=SMALL_BUFF))

        q1q2 = Line()
        q1q2.add_updater(lambda m:\
            m.put_start_and_end_on(
                q1.get_center(),
                self.get_opposite(q1)
            ))

        self.play(*[ShowCreation(e) for e in\
            [q2, q2_label, q1q2]])

        p1_y = ValueTracker(2)
        p1 = Dot()
        p1.set_fill(DARK_BLUE)
        p1.plot_depth = 1

        p1.add_updater(lambda m:\
            m.move_to(self.coords_to_point(
                self.func(p1_y.get_value()),
                p1_y.get_value()
            )))

        p1_label = TexMobject('P_1').scale(0.5)
        p1_label.add_updater(lambda m:\
            m.next_to(p1, RIGHT, buff=SMALL_BUFF))
        
        self.play(ShowCreation(p1), ShowCreation(p1_label))

        p2 = Dot()
        p2.set_fill(DARK_BLUE)
        p2.plot_depth = 1

        p2.add_updater(lambda m:\
            m.move_to(self.get_opposite(p1)))

        p2_label = TexMobject('P_2').scale(0.5)
        p2_label.add_updater(lambda m:\
            m.next_to(p2, RIGHT, buff=SMALL_BUFF))

        p1p2 = Line()
        p1p2.add_updater(lambda m:\
            m.put_start_and_end_on(
                p1.get_center(),
                self.get_opposite(p1)
            ))

        self.play(*[ShowCreation(e) for e in\
            [p2, p2_label, p1p2]])

        k1 = Dot()
        k1.set_fill(DARK_BROWN)
        k1.plot_depth = 1
        k1.add_updater(lambda m:\
            m.move_to(self.chord_to_directrix(p1, q1)))

        k1_label = TexMobject('K_1').scale(0.5)
        k1_label.add_updater(lambda m:\
            m.next_to(k1, LEFT, buff=SMALL_BUFF))

        p1q1 = Line()
        p1q1.add_updater(lambda m:\
            m.put_start_and_end_on(
                self.right(p1, q1),
                self.chord_to_directrix(p1, q1)
            ))
        p2q2 = Line()
        p2q2.add_updater(lambda m:\
            m.put_start_and_end_on(
                self.right(p2, q2),
                self.chord_to_directrix(p2, q2)
            ))

        self.play(*[ShowCreation(e) for e in \
            [k1, k1_label, p1q1, p2q2]])

        k2 = Dot()
        k2.set_fill(DARK_BROWN)
        k2.plot_depth = 1
        k2.add_updater(lambda m:\
            m.move_to(self.chord_to_directrix(p2, q1)))

        k2_label = TexMobject('K_2').scale(0.5)
        k2_label.add_updater(lambda m:\
            m.next_to(k2, LEFT, buff=SMALL_BUFF))

        p2q1 = Line()
        p2q1.add_updater(lambda m:\
            m.put_start_and_end_on(
                self.right(p2, q1),
                self.chord_to_directrix(p2, q1)
            ))
        p1q2 = Line()
        p1q2.add_updater(lambda m:\
            m.put_start_and_end_on(
                self.right(p1, q2),
                self.chord_to_directrix(p1, q2)
            ))

        self.play(*[ShowCreation(e) for e in \
            [k2, k2_label, p2q1, p1q2]])

        explain = CText('这些交点在准线上').scale(0.3)
        explain.to_edge(RIGHT)

        self.wait(2)
        self.play(Write(explain))
        self.wait(5)

        self.play(ApplyMethod(q1_y.set_value, 0.5),
            ApplyMethod(p1_y.set_value, -3))

        self.wait(3)
        self.play(ApplyMethod(q1_y.set_value, 3),
            ApplyMethod(p1_y.set_value, -9))
        self.wait(10)
コード例 #13
0
ファイル: prop2.py プロジェクト: codecxx/manim_sandbox
    def construct(self):
        self.adjust_x_range()
        graph = self.get_graph(color=DARK_BROWN)
        directrix = self.get_directrix()
        focus = Dot().move_to(self.get_focus())
        focus.set_fill(DARK_BROWN)
        focus.plot_depth = 1

        self.play(ShowCreation(graph), ShowCreation(directrix),
                  ShowCreation(focus))

        focus_label = TexMobject('F').scale(0.5)
        focus_label.next_to(focus, DOWN, buff=SMALL_BUFF)
        self.play(Write(focus_label))

        h_line = Line()
        d_loc = directrix.get_center()[0] * RIGHT
        h_line.put_start_and_end_on(d_loc, ORIGIN)
        h_line.plot_depth = -1
        self.play(ShowCreation(h_line))

        a = Dot()
        a.set_fill(LIGHT_BROWN)
        a.plot_depth = 1
        a.move_to(self.coords_to_point(0, 0))

        a_label = TexMobject('A').scale(0.5)
        a_label.next_to(a, DL, buff=SMALL_BUFF)

        t = Dot()
        t.set_fill(LIGHT_BROWN)
        t.plot_depth = 1
        t.move_to(d_loc)

        t_label = TexMobject('T').scale(0.5)
        t_label.next_to(t, LEFT, buff=SMALL_BUFF)

        y_value = ValueTracker(9)
        p = Dot()
        p.set_fill(DARK_BLUE)
        p.plot_depth = 1

        p.add_updater(lambda m:\
            m.move_to(self.value_to_point(
                y_value.get_value())))
        p_label = TexMobject('P').scale(0.5)
        p_label.add_updater(lambda m:\
            m.next_to(p, RIGHT, buff=SMALL_BUFF))

        m = Dot()
        m.set_fill(DARK_BLUE)
        m.plot_depth = 1
        m.add_updater(lambda t:\
            t.move_to(d_loc + p.get_center()[1] * UP))
        m_label = TexMobject('M').scale(0.5)
        m_label.add_updater(lambda l:\
            l.next_to(m, LEFT, buff=SMALL_BUFF))

        n = Dot()
        n.set_fill(DARK_BLUE)
        n.plot_depth = 1
        n.add_updater(lambda m:\
            m.move_to(p.get_center()[0] * RIGHT))

        n_label = TexMobject('N').scale(0.5)
        n_label.add_updater(lambda m:\
            m.next_to(n, DOWN, buff=SMALL_BUFF))

        self.play(*[ShowCreation(e) for e in\
            [a, p, m, n, t]])

        self.play(*[ShowCreation(e) for e in\
            [a_label, t_label, p_label, m_label, n_label]])
        self.wait()

        pn = Line()
        pn.add_updater(lambda l:\
            l.put_start_and_end_on(
                p.get_center(), n.get_center()))
        pf = Line()
        pf.add_updater(lambda l:\
            l.put_start_and_end_on(
                p.get_center(), focus.get_center()))

        pm = Line()
        pm.add_updater(lambda l:\
            l.put_start_and_end_on(
                p.get_center(), m.get_center()))
        self.play(*[ShowCreation(e) for e in\
            [pn, pf, pm]])
        self.wait()

        prop = VGroup()
        prop.add(CText('性质:')\
            .scale(0.25).set_color(DARK_BLUE))
        prop.add(TexMobject('PN^2=4AF\\cdot AN')\
            .scale(0.5)).set_color(DARK_BROWN)
        prop.arrange(RIGHT)

        proof = VGroup()
        prf = CText('证明:')\
            .scale(0.25).set_color(DARK_BLUE)
        proof.add(prf)

        details = VGroup()
        line1 = TexMobject('TN^2=', '(TA+AN)^2')\
            .scale(0.5)
        details.add(line1)

        line2 = TexMobject('TN^2=PM^2=PF^2')\
            .scale(0.5)
        details.add(line2)

        line3 = TexMobject('PF^2=PN^2+NF^2')\
            .scale(0.5)
        details.add(line3)

        line4 = TexMobject(
            'PN^2+NF^2=NF^2+4 AF\\cdot AN')\
            .scale(0.5)
        details.add(line4)

        line5 = TexMobject('PN^2=4AF\\cdot AN').scale(0.5).set_color(
            DARK_BROWN)
        details.add(line5)

        proof.add(details)
        details.arrange(DOWN)

        line2.align_to(line1, LEFT)
        line3.align_to(line2, LEFT)
        line4.align_to(line3, LEFT)
        line5.align_to(line4, LEFT)

        proof.arrange(RIGHT)
        prf.align_to(details, UP)

        forms = VGroup()
        forms.add(prop)
        forms.add(proof)
        forms.arrange(DOWN)
        proof.align_to(prop, LEFT)
        forms.to_edge(RIGHT, buff=2)

        expand = TexMobject('TA',
            '^2+AN^2+2', 'TA',
            '\\cdot AN')\
            .scale(0.5)
        expand.align_to(line1[1], LEFT)
        expand.align_to(line1[1], UP)

        expand2 = TexMobject('AF',
            '^2+AN^2+2', 'AF',
            '\\cdot AN')\
            .scale(0.5)
        expand2.align_to(line1[1], LEFT)
        expand2.align_to(line1[1], UP)

        expand3 = TexMobject(
            '(AF-AN)^2+4 AF\\cdot AN')\
            .scale(0.5)
        expand3.align_to(line1[1], LEFT)
        expand3.align_to(line1[1], UP)

        expand4 = TexMobject('NF^2+4 AF\\cdot AN').scale(0.5)
        expand4.align_to(line1[1], LEFT)
        expand4.align_to(line1[1], UP)

        self.play(Write(prop))
        self.wait()

        self.play(y_value.set_value, 1)
        self.wait()
        self.play(y_value.set_value, 3)
        self.wait()

        self.play(Write(prf))
        self.play(Write(line1))
        self.wait()

        self.play(ShowCreationThenDestruction(Line(t, n).set_color(RED)))
        self.play(ShowCreationThenDestruction(Line(t, a).set_color(RED)))
        self.play(ShowCreationThenDestruction(Line(a, n).set_color(RED)))
        self.wait()

        self.play(ReplacementTransform(line1[1], expand))
        self.wait(3)

        self.play(ShowCreationThenDestruction(Line(t, a).set_color(RED)))
        self.play(ShowCreationThenDestruction(Line(a, focus).set_color(RED)))
        self.wait()
        self.play(*[Transform(
            expand[e], expand2[e]) for e in\
            [0, 2]])
        self.wait(3)

        self.play(ReplacementTransform(expand, expand3))
        self.wait(3)
        self.play(ReplacementTransform(expand3, expand4))
        self.wait(3)

        self.play(Write(line2))
        self.play(ShowCreationThenDestruction(Line(t, n).set_color(RED)))
        self.play(ShowCreationThenDestruction(Line(p, m).set_color(RED)))
        self.play(ShowCreationThenDestruction(Line(p, focus).set_color(RED)))
        self.wait(3)

        self.play(Write(line3))
        self.play(
            ShowCreationThenDestruction(
                Polygon(p.get_center(), n.get_center(),
                        focus.get_center()).set_fill(DARK_BLUE, opacity=1)))
        self.wait(3)

        self.play(WiggleOutThenIn(expand4), WiggleOutThenIn(line3))

        self.play(Write(line4))
        self.wait(3)
        self.play(Write(line5))
        self.wait(3)

        def1 = CText('AF是焦距')
        def2 = CText('AN是点P的横标线')
        def3 = CText('PN是点P的纵标线')
        defines = VGroup(def1, def2, def3)
        defines.arrange(DOWN)
        defines.scale(0.25)
        defines.next_to(proof, DOWN)

        self.play(Write(defines))
        self.wait(5)

        self.play(y_value.set_value, 8)
        self.wait(10)
コード例 #14
0
    def construct(self):
        self.adjust_x_range()
        sub1 = CText('已知准线与焦点')
        sub1.scale(0.3)
        sub1.to_edge(RIGHT)
        self.play(Write(sub1))
        directrix = self.get_directrix()
        focus = Dot()
        focus.move_to(self.get_focus())
        focus.set_fill(DARK_BROWN)
        focus.plot_depth = 1
        focus_label = TexMobject('F').scale(0.5)
        focus_label.next_to(focus, RIGHT + UP,\
            buff=SMALL_BUFF)
        self.play(*[ShowCreation(e) for e in [directrix, focus, focus_label]])

        sub2 = CText('先找到顶点A')
        sub2.scale(0.3)
        sub2.to_edge(RIGHT)

        self.wait()
        self.play(FadeOut(sub1))
        self.play(Write(sub2))

        fl = Line(directrix.get_center(), focus.get_center())
        a = Dot()
        a.move_to(fl.get_center())
        a.set_fill(DARK_BROWN)
        a.plot_depth = 1
        a_label = TexMobject('A').scale(0.5)
        a_label.next_to(a, RIGHT + UP,\
            buff=SMALL_BUFF)
        self.play(ShowCreation(fl))
        self.play(ShowCreation(a))
        self.play(FadeOut(fl), ShowCreation(a_label))

        y_val = ValueTracker(4)

        sub3 = CText('在准线上任取一点')
        sub3.scale(0.3)
        sub3.to_edge(RIGHT)
        self.play(FadeOut(sub2))
        self.play(Write(sub3))

        m = Dot()
        m.set_fill(DARK_BLUE)
        m.plot_depth = 1
        m.add_updater(lambda m:\
            m.move_to(self.coords_to_point(
                -self.focus, y_val.get_value()
            )))
        m_label = TexMobject('M').scale(0.5)
        m_label.add_updater(lambda l: l.next_to(m, LEFT))
        self.play(ShowCreation(m), ShowCreation(m_label))

        self.wait()
        sub4 = CText('连接相应的点')
        sub4.scale(0.3)
        sub4.to_edge(RIGHT)
        self.play(FadeOut(sub3))
        self.play(Write(sub4))

        ma = Line()
        ma.add_updater(lambda l:\
            l.put_start_and_end_on(
                m.get_center(),
                a.get_center()
            ))

        af = Line(a.get_center(), focus.get_center() + RIGHT)

        mf = Line()
        mf.add_updater(lambda l:\
            l.put_start_and_end_on(
                m.get_center(),
                focus.get_center()
            ))

        self.play(*[ShowCreation(e) for e in [af, mf, ma]])
        self.wait()

        sub5 = CText('延长MA, MF')
        sub5.scale(0.3)
        sub5.to_edge(RIGHT)
        self.play(FadeOut(sub4))
        self.play(Write(sub5))

        def get_ma_extent():
            vec = a.get_center() - m.get_center()
            vec *= FRAME_WIDTH
            return a.get_center() + vec

        ma_extent = Line()
        ma_extent.add_updater(lambda l:\
            l.put_start_and_end_on(
                a.get_center(),
                get_ma_extent()
            ))

        def get_mf_extent():
            vec = focus.get_center() - m.get_center()
            return focus.get_center() + normalize(vec)

        mf_extent = Line()
        mf_extent.add_updater(lambda l:\
            l.put_start_and_end_on(
                focus.get_center(),
                get_mf_extent()
            ))

        self.play(ShowCreation(mf_extent), ShowCreation(ma_extent))

        self.wait()
        sub6 = CText('做对称线(相等的角)')
        sub6.scale(0.3)
        sub6.to_edge(RIGHT)
        self.play(FadeOut(sub5))
        self.play(Write(sub6))

        def get_flip():
            loc = get_mf_extent()
            f = focus.get_center()
            x = loc[0] - f[0]
            y = loc[1] - f[1]
            ang = 2 * np.arctan2(y, x)
            vec = np.cos(ang) * RIGHT + np.sin(ang) * UP
            return vec

        mf_flip = Line()
        mf_flip.add_updater(lambda l:\
            l.put_start_and_end_on(
                focus.get_center(),
                get_flip() + focus.get_center()
            ))

        self.play(ShowCreation(mf_flip))

        sub7 = CText('交MA于点P')
        sub7.scale(0.3)
        sub7.to_edge(RIGHT)
        self.play(FadeOut(sub6))
        self.play(Write(sub7))

        mf_flip_extent = Line()
        mf_flip_extent.add_updater(lambda l:\
            l.put_start_and_end_on(
                focus.get_center(),
                get_flip() * FRAME_WIDTH\
                    + focus.get_center()
            ))
        self.play(ShowCreation(mf_flip_extent))

        def get_p():
            x1 = m.get_center()[0]
            y1 = m.get_center()[1]
            x2 = a.get_center()[0]
            y2 = a.get_center()[1]
            x3 = focus.get_center()[0]
            y3 = focus.get_center()[1]
            vec = get_flip()
            x4 = x3 + vec[0]
            y4 = y3 + vec[1]

            a1 = y2 - y1
            b1 = x1 - x2
            c1 = a1 * x1 + b1 * y1

            a2 = y4 - y3
            b2 = x3 - x4
            c2 = a2 * x3 + b2 * y3

            determinant = a1 * b2 - a2 * b1

            if determinant == 0:
                return a.get_center()

            x = (b2 * c1 - b1 * c2) / determinant
            y = (a1 * c2 - a2 * c1) / determinant
            return x * RIGHT + y * UP

        p = Dot()
        p.set_fill(DARK_BLUE)
        p.plot_depth = 1
        p.add_updater(lambda m: m.move_to(get_p()))

        p_label = TexMobject('P').scale(0.5)
        p_label.add_updater(lambda m:\
            m.next_to(p, RIGHT, buff=SMALL_BUFF))
        self.play(ShowCreation(p), ShowCreation(p_label))

        self.wait(3)
        self.play(ApplyMethod(y_val.set_value, -4))

        graph = self.get_graph(color=LIGHT_BROWN)
        self.play(ShowCreation(graph))

        self.wait(3)
        self.play(ApplyMethod(y_val.set_value, -8))

        self.wait(3)
        self.play(ApplyMethod(y_val.set_value, -6))

        self.wait(3)
        self.play(ApplyMethod(y_val.set_value, 6))

        self.wait(3)
        self.play(ApplyMethod(y_val.set_value, 8))
        self.wait(10)
コード例 #15
0
    def construct(self):
        self.adjust_x_range()
        graph = self.get_graph(color=LIGHT_BROWN)
        focus = Dot(self.get_focus()).set_fill(DARK_BLUE)
        directrix = self.get_directrix()
        focusLabel = TexMobject('F').scale(0.75)
        focusLabel.next_to(focus, RIGHT, buff=SMALL_BUFF)
        self.directrix = directrix
        focus.plot_depth = 1

        sub1 = CText('在抛物线上任取不同的两点P1,P2').scale(0.4)
        sub1.to_corner(RIGHT + DOWN)

        p1_y = ValueTracker(7)
        p2_y = ValueTracker(2)

        p1 = Dot()
        p1.add_updater(
            lambda m: m.move_to(self.value_to_point(p1_y.get_value())))
        p1.plot_depth = 1

        p2 = Dot()
        p2.add_updater(
            lambda m: m.move_to(self.value_to_point(p2_y.get_value())))
        p2.plot_depth = 1

        p1.set_fill(RED)
        p2.set_fill(RED)

        p1Label = TexMobject('P_1').scale(0.75)
        p2Label = TexMobject('P_2').scale(0.75)

        p1Label.add_updater(lambda m:\
            m.next_to(p1, RIGHT, buff=SMALL_BUFF))
        p2Label.add_updater(lambda m:\
            m.next_to(p2, LEFT+UP, buff=SMALL_BUFF))

        sub2 = CText('连接两点,延长交准线于点K')
        sub2.scale(0.4).to_corner(RIGHT + DOWN)

        ppLine = Line()

        ppLine.add_updater(lambda m:\
            m.put_start_and_end_on(p1.get_center(),\
            self.get_directrix_point(p1, p2)))

        k = Dot()
        k.plot_depth = 1
        k.set_fill(DARK_BLUE)
        k.add_updater(lambda m: m.move_to(ppLine.points[-1]))

        kLabel = TexMobject('K').scale(0.75)
        kLabel.add_updater(lambda m:\
            m.next_to(k, LEFT, buff=SMALL_BUFF))

        sub3 = CText('分别连接P1F, P2F')
        sub3.scale(0.4).to_corner(RIGHT + DOWN)

        p1f = Line()
        p2f = Line()
        p1f.add_updater(lambda m:\
            m.put_start_and_end_on(p1.get_center(),\
            focus.get_center()))
        p2f.add_updater(lambda m:\
            m.put_start_and_end_on(p2.get_center(),\
            focus.get_center()))

        sub4 = CText('延长P1F交准线于D')
        sub4.scale(0.4).to_corner(RIGHT + DOWN)

        p1fd = Line()
        p1fd.add_updater(lambda m:\
            m.put_start_and_end_on(\
            focus.get_center(),\
            self.get_directrix_point(p1, focus)))
        d = Dot()
        d.plot_depth = 1
        d.set_fill(DARK_BLUE)
        d.add_updater(lambda m: m.move_to(p1fd.points[-1]))
        dLabel = TexMobject('D')
        dLabel.scale(0.75)
        dLabel.add_updater(lambda m:\
            m.next_to(d, LEFT, buff=SMALL_BUFF))

        sub5 = CText('连接KF')
        sub5.scale(0.4).to_corner(RIGHT + DOWN)

        kf = Line()
        kf.add_updater(lambda m:\
            m.put_start_and_end_on\
            (k.get_center(), focus.get_center()))

        ang1 = ArcBetweenPoints(*self.get_arc_point(
            p2.get_center(), focus.get_center(), k.get_center()))
        ang1.add_updater(lambda m:\
            m.put_start_and_end_on(
                *self.get_arc_point(
                p2.get_center(),
                focus.get_center(),
                k.get_center()
            )))
        ang1Label = TexMobject('1').scale(0.5)
        ang1Label.add_updater(lambda m:\
            m.move_to(ang1.get_center()))

        ang2 = ArcBetweenPoints(*self.get_arc_point(
            k.get_center(), focus.get_center(), d.get_center()))
        ang2.add_updater(lambda m:\
            m.put_start_and_end_on(
                *self.get_arc_point(
                k.get_center(),
                focus.get_center(),
                d.get_center()
            )))
        ang2Label = TexMobject('2').scale(0.5)
        ang2Label.add_updater(lambda m:\
            m.move_to(ang2.get_center()))

        ang1Value = DecimalNumber(self.get_angle(
            p2.get_center(), focus.get_center(), k.get_center()) / DEGREES,
                                  num_decimal_places=2)
        ang1Value.add_updater(lambda m:\
            m.set_value(self.get_angle(
                p2.get_center(),
                focus.get_center(),
                k.get_center()
            ) / DEGREES))
        ang2Value = DecimalNumber(self.get_angle(
            k.get_center(), focus.get_center(), d.get_center()) / DEGREES,
                                  num_decimal_places=2)
        ang2Value.add_updater(lambda m:\
            m.set_value(self.get_angle(
                k.get_center(),
                focus.get_center(),
                d.get_center()
            ) / DEGREES))

        ang1Tail = TexMobject('^{\circ}')
        ang2Tail = TexMobject('^{\circ}')

        ang1head = TexMobject('\\angle 1=')
        ang1Text = VGroup(ang1head, ang1Value, ang1Tail)
        ang1Text.arrange(buff=SMALL_BUFF)
        ang1Tail.shift(0.15 * UP)

        ang2head = TexMobject('\\angle 2=')
        ang2Text = VGroup(ang2head, ang2Value, ang2Tail)
        ang2Text.arrange(buff=SMALL_BUFF)
        ang2Tail.shift(0.15 * UP)

        angs = VGroup(ang1Text, ang2Text)
        angs.arrange(buff=MED_SMALL_BUFF)
        angs.shift(3 * RIGHT + 2 * UP)

        m1 = Dot()
        m1.plot_depth = 1
        m1.set_fill(ORANGE)
        m1.add_updater(lambda m:\
            m.move_to(self.coords_to_point(
                -self.focus, p1_y.get_value()
            )))

        m2 = Dot()
        m2.plot_depth = 1
        m2.set_fill(ORANGE)
        m2.add_updater(lambda m:\
            m.move_to(self.coords_to_point(
                -self.focus, p2_y.get_value()
            )))

        m1Label = TexMobject('M_1').scale(0.75)
        m2Label = TexMobject('M_2').scale(0.75)
        m1Label.add_updater(lambda m:\
            m.next_to(m1, LEFT, buff=SMALL_BUFF))
        m2Label.add_updater(lambda m:\
            m.next_to(m2, LEFT, buff=SMALL_BUFF))

        m1p1 = DashedLine()
        m1p1.add_updater(lambda m:\
            m.put_start_and_end_on(
                m1.get_center(), p1.get_center()
            ))
        m2p2 = DashedLine()
        m2p2.add_updater(lambda m:\
            m.put_start_and_end_on(
                m2.get_center(), p2.get_center()
            ))

        fracs = TexMobject('{KP_2', '\\over', 'KP_1}', '=', '{M_2P_2',
                           '\\over', 'M_1P_1}', '=', '{FP_2', '\\over',
                           'FP_1}')
        fracs.shift(3 * RIGHT + 2 * UP)

        fracs2 = TexMobject('{KP_2', '\\over', 'KP_1}', '=', '{FP_2', '\\over',
                            'FP_1}')
        fracs2.move_to(fracs.get_center())
        fracs2.align_to(fracs, LEFT)

        fracs3 = TexMobject('{KP_2', '\\over', 'FP_2}', '=', '{KP_1', '\\over',
                            'FP_1}')
        fracs3.move_to(fracs2.get_center())

        explain = CText('由正弦定理').scale(0.4)
        explain.next_to(fracs3, DOWN)
        explain.align_to(fracs3, LEFT)

        fracs4 = TexMobject('{\\sin\\angle 1', '\\over', '\\sin\\angle K}',
                            '=', '{\\sin\\angle KFP_1', '\\over',
                            '\\sin\\angle K}')
        fracs4.next_to(explain, DOWN)
        fracs4.align_to(explain, LEFT)

        form = TexMobject('\\sin \\angle 1 = \\sin \\angle KFP_1')
        form.next_to(fracs4, DOWN)
        form.align_to(fracs4, LEFT)

        form2 = TexMobject('\\angle1 < \\angle KFP_1 < \\pi')
        form2.next_to(form, DOWN)
        form2.align_to(form, LEFT)

        form3 = TexMobject('\\angle1 = \pi - \\angle KFP_1 = \\angle 2')
        form3.next_to(form2, DOWN)
        form3.align_to(form2, LEFT)

        remover = Rectangle(height=FRAME_HEIGHT, width=FRAME_WIDTH)
        remover.set_color(BLACK)
        remover.set_fill(BLACK, opacity=1)
        remover.plot_depth = 2
        # kp2 = Line()
        # kp2.add_updater(lambda m:\
        #     m.put_start_and_end_on(k.get_center(),
        #     p2.get_center()))
        # kp2.set_color(YELLOW)
        ############################################
        # Animation part                           #
        ############################################
        self.play(ShowCreation(focus), ShowCreation(directrix))
        self.play(ShowCreation(graph), Write(focusLabel))

        self.play(Write(sub1))
        self.play(*[ShowCreation(e) for e in\
            [p1, p2, p1Label, p2Label]])
        self.wait()

        self.play(FadeOut(sub1))
        self.play(Write(sub2))

        self.wait()
        self.play(ShowCreation(ppLine))
        self.play(ShowCreation(k), Write(kLabel))

        self.wait()
        self.play(FadeOut(sub2))
        self.play(Write(sub3))

        self.play(*[ShowCreation(e) for e in [p1f, p2f]])

        self.wait()
        self.play(FadeOut(sub3))
        self.play(Write(sub4))

        self.play(ShowCreation(p1fd))
        self.play(*[ShowCreation(e) for e in [d, dLabel]])

        self.wait()
        self.play(FadeOut(sub4))
        self.play(Write(sub5))

        self.wait()
        self.play(ShowCreation(kf))
        self.play(ShowCreation(ang1), Write(ang1Label))
        self.play(ShowCreation(ang2), Write(ang2Label))
        self.play(FadeOut(sub5))

        self.play(Write(angs))

        self.play(*[ShowCreation(e) for e in\
            [m1, m2, m1p1, m2p2, m1Label, m2Label]])

        self.play(ApplyMethod(p2_y.set_value, -1), run_time=2)
        self.wait()
        self.play(ApplyMethod(p1_y.set_value, 5))
        self.wait()
        self.play(ApplyMethod(p1_y.set_value, 9), run_time=3)
        self.wait()
        self.play(ApplyMethod(p2_y.set_value, 3), run_time=2)

        self.play(FadeOut(angs))
        self.wait()

        self.play(Write(fracs))
        self.wait(5)
        #self.play(ReplacementTransform(fracs, fracs2))
        self.play(FadeOut(fracs[4:8]))
        self.play(*[
            ApplyMethod(fracs[i].move_to, fracs[i - 4].get_center())
            for i in range(8, 11)
        ])

        # self.play(FadeOut(fracs), FadeIn(fracs2), run_time=0.1)

        # self.wait(5)
        # self.play(ReplacementTransform(fracs2, fracs3))
        self.wait(5)
        pos1 = fracs[2].get_center()
        pos2 = fracs[8].get_center()
        self.play(ApplyMethod(fracs[2].move_to, pos2),
                  ApplyMethod(fracs[8].move_to, pos1))

        self.wait(5)
        self.play(Write(explain))
        self.wait(3)

        self.play(ShowCreationThenDestruction(
            Polygon(k.get_center(), focus.get_center(),
                    p2.get_center()).set_fill(DARK_BLUE, opacity=1)),
                  run_time=3)
        self.play(Write(fracs4[:3]))

        self.play(ShowCreationThenDestruction(
            Polygon(k.get_center(), focus.get_center(),
                    p1.get_center()).set_fill(DARK_BLUE, opacity=1)),
                  run_time=3)
        self.play(Write(fracs4[3:]))

        self.wait(3)
        self.play(Write(form))
        self.wait(3)
        self.play(Write(form2))
        self.wait(3)
        self.play(Write(form3))
        self.wait(5)

        self.play(FadeIn(remover))
コード例 #16
0
    def construct(self):
        self.adjust_x_range()
        graph = self.get_graph(color=LIGHT_BROWN)
        directrix = self.get_directrix()
        focus = Dot().move_to(self.get_focus())
        focus.set_fill(DARK_BROWN)
        focus.plot_depth = 1
        focusLabel = TexMobject('F').scale(0.5)
        focusLabel.next_to(focus, RIGHT + UP)

        self.play(*[ShowCreation(e) for\
            e in [graph, directrix, focus, focusLabel]])

        h_line = self.get_horizontal()
        x = Dot()
        x.set_fill(DARK_BROWN)
        x.plot_depth = 1
        x.move_to(self.coords_to_point(-self.focus, 0))
        x_label = TexMobject('X').scale(0.5)
        x_label.next_to(x, LEFT + UP)

        self.play(ShowCreation(h_line))
        self.play(ShowCreation(x), ShowCreation(x_label))

        y_val = ValueTracker(8)
        p = Dot()
        p.set_fill(DARK_BLUE)
        p.plot_depth = 1
        p.add_updater(lambda m:\
            m.move_to(self.coords_to_point(
                self.func(y_val.get_value()),
                y_val.get_value()
            )))
        
        q = Dot()
        q.set_fill(DARK_BLUE)
        q.plot_depth = 1
        q.add_updater(lambda m:\
            m.move_to(self.coords_to_point(
                self.func(-y_val.get_value()),
                -y_val.get_value()
            )))

        t = Dot()
        t.set_fill(DARK_BLUE)
        t.plot_depth = 1
        t.add_updater(lambda m:\
            m.move_to(self.coords_to_point(
                self.func(y_val.get_value()), 0
            )))

        p_label = TexMobject('P').scale(0.5)
        p_label.add_updater(lambda m:\
            m.next_to(p, RIGHT))
        q_label = TexMobject('Q').scale(0.5)
        q_label.add_updater(lambda m:\
            m.next_to(q, RIGHT))
        t_label = TexMobject('T').scale(0.5)
        t_label.add_updater(lambda m:\
            m.next_to(t, RIGHT + UP))

        pq = Line()
        pq.add_updater(lambda m:\
            m.put_start_and_end_on(
                p.get_center(),
                self.coords_to_point(
                    self.func(-y_val.get_value()),
                    -y_val.get_value()
            )))
        pt = Line()
        pt.add_updater(lambda m:\
            m.put_start_and_end_on(
                p.get_center(),
                self.coords_to_point(
                    self.func(y_val.get_value()), 0
                )))
        self.play(ShowCreation(p), ShowCreation(p_label))
        self.play(ShowCreation(pt))
        self.play(ShowCreation(t), ShowCreation(t_label))
        label1 = CText('纵标线').scale(0.3)\
                .next_to(pt, RIGHT)
        self.play(ShowCreation(label1))
        self.wait()
        self.play(FadeOut(label1))
        self.play(ShowCreation(pq))
        self.remove(pt)
        self.play(ShowCreation(q), ShowCreation(q_label))
        label2 = CText('双纵标线').scale(0.3)\
                .next_to(t, RIGHT+DOWN)
        self.play(ShowCreation(label2))
        self.wait()
        self.play(FadeOut(label2))
        self.wait()
        
        inter = Dot()
        inter.set_fill(DARK_BLUE)
        inter.plot_depth = 1
        inter.add_updater(lambda m:\
            m.move_to(
                self.coords_to_point(
                    4*(self.focus**3)/(y_val.get_value()**2),
                    4*self.focus**2/y_val.get_value()
                ) if y_val.get_value() != 0 else
                    self.coords_to_point(0, 0)
            ))

        inter_label = TexMobject("P'").scale(0.5)
        inter_label.add_updater(lambda m:\
            m.next_to(inter, LEFT + UP, buff=SMALL_BUFF))

        px = Line()
        px.add_updater(lambda m:\
            m.put_start_and_end_on(
                self.right(p, inter),
                x.get_center()
            ))
        
        self.play(ShowCreation(px))
        self.play(ShowCreation(inter),
            ShowCreation(inter_label))
        self.wait()

        form = CText("P'Q经过焦点").shift(UP)
        form.scale(0.5)
        form.to_edge(RIGHT)
        self.play(Write(form))
        
        interq = Line()
        interq.add_updater(lambda m:\
            m.put_start_and_end_on(
                inter.get_center(),
                q.get_center()
            ))
        self.play(ShowCreation(interq))

        self.wait(2)
        self.play(ApplyMethod(y_val.set_value, 4))

        self.wait(2)
        self.play(ApplyMethod(y_val.set_value, -4))

        self.wait(2)
        self.play(ApplyMethod(y_val.set_value, -9))

        self.wait(2)
        self.play(ApplyMethod(y_val.set_value, 9))

        self.wait(10)
コード例 #17
0
    def construct(self):
        self.adjust_x_range()
        graph = self.get_graph(color=LIGHT_BROWN)
        directrix = self.get_directrix()
        focus = Dot().move_to(self.get_focus())
        focus.set_fill(DARK_BROWN)
        focus.plot_depth = 1
        focusLabel = TexMobject('F').scale(0.7)
        focusLabel.next_to(focus, RIGHT)

        self.play(*[ShowCreation(e) for\
            e in [graph, directrix, focus, focusLabel]])

        y_val = ValueTracker(8)

        p1 = Dot()
        p1.set_color(DARK_BLUE)
        p1.add_updater(lambda m:\
            m.move_to(self.coords_to_point(
                self.func(y_val.get_value()),
                y_val.get_value()
            )))
        p1.plot_depth = 1

        p1Label = TexMobject('P_1').scale(0.7)
        p1Label.add_updater(lambda m:\
            m.next_to(p1, RIGHT, buff=SMALL_BUFF))

        p2 = Dot()
        p2.set_color(DARK_BLUE)
        p2.add_updater(lambda m:\
            m.move_to(self.get_opposite(p1)))
        p2.plot_depth = 1

        p2Label = TexMobject('P_2').scale(0.7)
        p2Label.add_updater(lambda m:\
            m.next_to(p2, RIGHT, buff=SMALL_BUFF))

        focus_chord = Line()
        focus_chord.add_updater(lambda m:\
            m.put_start_and_end_on(
                p1.get_center(),
                self.get_opposite(p1)
            ))

        self.play(ShowCreation(p1), ShowCreation(p1Label))
        self.play(ShowCreation(focus_chord))
        self.play(ShowCreation(p2), ShowCreation(p2Label))

        fc_def = CText('焦点弦')
        fc_def.move_to(focus_chord.get_center())
        fc_def.shift(0.2 * RIGHT + 0.1 * DOWN)
        self.play(Write(fc_def))
        self.wait(2)
        self.play(FadeOut(fc_def))
        
        q_y = ValueTracker(2)
        q = Dot()
        q.set_fill(DARK_BLUE)
        q.plot_depth = 1

        q.add_updater(lambda m:\
            m.move_to(self.coords_to_point(
                self.func(q_y.get_value()),
                q_y.get_value()
            )))

        qLabel = TexMobject('Q').scale(0.7)
        qLabel.add_updater(lambda m:\
            m.next_to(q, LEFT, buff=SMALL_BUFF))
        
        k1 = Dot()
        k1.set_fill(BLUE_E)
        k1.plot_depth = 1
        k1.add_updater(lambda m:\
            m.move_to(self.chord_to_directrix(p1, q)))

        k1Label = TexMobject('K_1').scale(0.7)
        k1Label.add_updater(lambda m:\
            m.next_to(k1, LEFT, buff=SMALL_BUFF))

        k2 = Dot()
        k2.set_fill(BLUE_E)
        k2.plot_depth = 1
        k2.add_updater(lambda m:\
            m.move_to(self.chord_to_directrix(p2, q)))

        k2Label = TexMobject('K_2').scale(0.7)
        k2Label.add_updater(lambda m:\
            m.next_to(k2, LEFT, buff=SMALL_BUFF))
        
        l1 = Line()
        l1.add_updater(lambda m:\
            m.put_start_and_end_on(
                self.right(p1, q),
                self.chord_to_directrix(p1, q)
            ))

        l2 = Line()
        l2.add_updater(lambda m:\
            m.put_start_and_end_on(
                self.right(p2, q),
                self.chord_to_directrix(p2, q)
            ))
        
        self.play(ShowCreation(q), ShowCreation(qLabel))
        self.play(ShowCreation(l1), ShowCreation(l2))
        self.play(*[ShowCreation(e) for e in [k1, k2, k1Label, k2Label]])

        k1f = Line()
        k1f.add_updater(lambda m:\
            m.put_start_and_end_on(
                k1.get_center(), focus.get_center()
            ))

        k2f = Line()
        k2f.add_updater(lambda m:\
            m.put_start_and_end_on(
                k2.get_center(), focus.get_center()
            ))

        self.play(ShowCreation(k1f), ShowCreation(k2f))

        self.wait(1)
        self.play(ApplyMethod(y_val.set_value,
            5))

        summary = TexMobject('K_1F \\perp K_2F').scale(2)
        summary.to_edge(RIGHT)

        self.wait(1)
        self.play(Write(summary))
        self.wait(5)

        qf = Line()
        qf.add_updater(lambda m:\
            m.put_start_and_end_on(q.get_center(),
                focus.get_center()))
        self.play(ShowCreation(qf))

        self.wait(1)
        self.play(ApplyMethod(q_y.set_value,
            -1))

        self.wait(1)
        self.play(ApplyMethod(y_val.set_value,
            0.5))

        self.wait(1)
        self.play(ApplyMethod(y_val.set_value,
            3),
            ApplyMethod(q_y.set_value, 0.5))
        self.wait(10)
コード例 #18
0
    def construct(self):
        self.adjust_x_range()
        lineCText = CText('设有一固定直线l')
        directrix = self.get_directrix()
        self.play(Write(lineCText))
        self.play(ApplyMethod(lineCText.scale, 0.3), ShowCreation(directrix))
        self.play(
            ApplyMethod(lineCText.move_to,
                        self.coords_to_point(-self.focus + 3,
                                             self.y_max - 2)), )

        self.wait()

        focusCText = CText('有一固定点F')
        focus = Circle()\
            .move_to(self.get_focus())\
            .scale(0.1)\
            .set_fill(ORANGE, opacity=1)
        self.play(Write(focusCText))
        self.wait()
        self.play(ApplyMethod(focusCText.scale, 0.3))
        self.play(
            ApplyMethod(focusCText.move_to,
                        self.coords_to_point(self.focus + 3, 0)),
            ShowCreation(focus))
        self.wait()

        question = CText('求到直线距离l与到\n点P距离相等的点的轨迹')
        question.scale(0.4)
        question.to_edge(RIGHT)

        self.play(Write(question))
        self.wait()

        pickPoint = CText('在l上任取一点P')
        pickPoint.scale(0.4)
        pickPoint.to_edge(DOWN)

        self.play(Write(pickPoint))

        y = ValueTracker(5)
        point = Circle()\
            .scale(0.1)\
            .set_fill(ORANGE, opacity=1)\
            .move_to(self.coords_to_point(-self.focus, y.get_value()))
        self.play(ShowCreation(point))

        self.wait()
        self.play(FadeOut(pickPoint))

        connect = CText('连接FP')
        connect.scale((0.4))
        connect.to_edge(DOWN)
        fp = DashedLine(point.get_center(), focus.get_center())

        self.play(Write(connect))
        self.play(ShowCreation(fp))
        self.wait()

        midRight = CText('做FP中垂线')
        midRight.scale(0.4)
        midRight.to_edge(DOWN)
        midPoint = Circle()\
            .scale(0.1)\
            .move_to((point.get_center() + focus.get_center())/2)\
            .set_fill(DARK_BLUE, opacity=1).set_color(DARK_BLUE)

        midRightLine = DashedLine(LEFT * FRAME_WIDTH, RIGHT * FRAME_WIDTH)
        midRightLine.rotate(fp.get_angle() + np.pi / 2,
                            about_point=midRight.get_center())
        midRightLine.move_to(midPoint.get_center())

        self.play(FadeOut(connect))
        self.play(Write(midRight))
        self.play(ShowCreation(midPoint))
        self.play(ShowCreation(midRightLine))
        self.wait()

        right = CText('过P点做l的垂线')
        right.scale(0.4)
        right.to_edge(DOWN)

        rightLine = DashedLine(LEFT * FRAME_WIDTH, RIGHT * FRAME_WIDTH)
        rightLine.shift(UP * (point.get_center()[1]))

        self.play(FadeOut(midRight))
        self.play(Write(right))
        self.play(ShowCreation(rightLine))

        targetCText = CText('垂线与中垂线交点即为曲线上的点')
        targetCText.scale(0.4).to_edge(DOWN)
        target = Circle()\
            .scale(0.1)\
            .set_fill(RED, opacity=1)\
            .set_color(ORANGE)\
            .move_to(self.value_to_point(y.get_value()))

        self.play(FadeOut(right))
        self.play(Write(targetCText))
        self.play(DrawBorderThenFill(target))

        point.add_updater(lambda m: m.move_to(
            self.coords_to_point(-self.focus, y.get_value())))
        fp.add_updater(lambda m: m.put_start_and_end_on(
            point.get_center(), focus.get_center()))
        midPoint.add_updater(lambda m: m.move_to(
            (point.get_center() + focus.get_center()) / 2))
        rightLine.add_updater(lambda m: m.move_to(point.get_center()))
        target.add_updater(
            lambda m: m.move_to(self.value_to_point(y.get_value())))

        def setRight(line):
            line.put_start_and_end_on(LEFT * FRAME_WIDTH, RIGHT * FRAME_WIDTH)
            line.rotate(fp.get_angle() + np.pi / 2,
                        about_point=midRight.get_center())
            line.move_to(midPoint.get_center())

        midRightLine.add_updater(setRight)

        self.play(ApplyMethod(y.set_value, -2))

        graph = self.get_graph(color=LIGHT_BROWN)
        self.play(ApplyMethod(y.set_value, -8), ShowCreation(graph))
        self.wait()
        self.play(ApplyMethod(y.set_value, 8, run_time=2))
        self.wait()

        self.play(ApplyMethod(y.set_value, 2, run_time=2))

        directDef = CText('直线l称为准线')
        directDef.scale(0.4)
        directDef.to_edge(DOWN)

        dire = CText('准线')
        dire.scale(0.3).move_to(lineCText.get_center())
        dire.align_to(lineCText, LEFT)

        self.play(FadeOut(targetCText))
        self.play(Write(directDef))
        self.play(Transform(lineCText, dire))

        self.wait()
        self.play(FadeOut(directDef))

        focDef = CText('点F称为焦点')
        focDef.scale(0.4).to_edge(DOWN)
        foc = CText('焦点')
        foc.scale(0.3).move_to(focusCText.get_center())\
            .align_to(focusCText, LEFT)

        self.play(Write(focDef))
        self.play(Transform(focusCText, foc))
        self.wait(3)

        self.play(ShowCreation(self.get_horizontal()))
        self.play(Write(CText('轴')\
            .scale(0.3).move_to(self.coords_to_point(5, 0.5))))
        self.play(ShowCreation(
            Circle()\
                .scale(0.1)\
                .set_color(DARK_BLUE)\
                .set_fill(DARK_BLUE, opacity=1)\
                .move_to(self.coords_to_point(0, 0))
        ))
        self.play(Write(CText('顶点')\
            .scale(0.3).move_to(self.coords_to_point(0.5, 0.5))))
        self.wait(3)
コード例 #19
0
    def construct(self):
        self.adjust_x_range()
        graph = self.get_graph(color=LIGHT_BROWN)
        directrix = self.get_directrix()
        focus = Dot().move_to(self.get_focus())
        focus.set_fill(DARK_BROWN)
        focus.plot_depth = 1
        focusLabel = TexMobject('F').scale(0.5)
        focusLabel.next_to(focus, DOWN, buff=SMALL_BUFF)

        self.play(*[ShowCreation(e) for\
            e in [graph, directrix, focus, focusLabel]])

        y_val = ValueTracker(8)

        p1 = Dot()
        p1.set_color(DARK_BLUE)
        p1.add_updater(lambda m:\
            m.move_to(self.coords_to_point(
                self.func(y_val.get_value()),
                y_val.get_value()
            )))
        p1.plot_depth = 1

        p1_label = TexMobject('P_1').scale(0.5)
        p1_label.plot_depth = 1
        p1_label.add_updater(lambda m:\
            m.next_to(p1, RIGHT, buff=SMALL_BUFF))

        p2 = Dot()
        p2.plot_depth = 1
        p2.set_color(DARK_BLUE)
        p2.add_updater(lambda m:\
            m.move_to(self.coords_to_point(
                self.func(-y_val.get_value()),
                -y_val.get_value()
            )))

        p2_label = TexMobject('P_2').scale(0.5)
        p2_label.plot_depth = 1
        p2_label.add_updater(lambda m:\
            m.next_to(p2, RIGHT, buff=SMALL_BUFF))

        a = Dot()
        a.set_color(DARK_BLUE)
        a.plot_depth = 1
        a.move_to(self.coords_to_point(0, 0))

        a_label = TexMobject('A').scale(0.5)
        a_label.next_to(a, DL, buff=SMALL_BUFF)

        h_line = Line(LEFT*6, RIGHT*2)

        self.play(*[ShowCreation(e) for e in\
            [h_line, a, a_label]])
        self.wait()

        sub1 = CText('取任意双纵标线P1P2')\
            .scale(0.3).to_edge(RIGHT)
        self.play(Write(sub1))
        self.wait()
        self.play(*[ShowCreation(e) for e in\
            [p1, p1_label, p2, p2_label]])

        p1p2 = Line()
        p1p2.add_updater(lambda l:\
            l.put_start_and_end_on(
                p1.get_center(), p2.get_center()
            ))
        self.play(ShowCreation(p1p2))
        self.wait()

        n = Dot()
        n.set_color(DARK_BLUE)
        n.plot_depth = 1
        n.add_updater(lambda m:\
            m.move_to(self.coords_to_point(
                self.func(y_val.get_value()), 0
            )))
        n_label = TexMobject('N').scale(0.5)
        n_label.plot_depth = 1
        n_label.add_updater(lambda m:\
            m.next_to(n, DR, buff=SMALL_BUFF))
        self.play(
            ShowCreation(n),
            ShowCreation(n_label)
        )
        self.wait()

        sub2 = CText('做P1、P2、A的外接圆')\
            .scale(0.3).to_edge(RIGHT)
        self.play(FadeOut(sub1))
        self.play(Write(sub2))

        def set_circle(c):
            pos1 = a.get_center()
            pos2 = p1.get_center()
            pos3 = p2.get_center()

            p = self.focus
            y = y_val.get_value()
            o = self.coords_to_point(
                (16*p*p+y*y)/(8*p), 0
            )

            r = o[0] - pos1[0]
            c.move_to(o)
            c.stretch_to_fit_height(2 * r)
            c.stretch_to_fit_width(2 * r)
            
        circle = Circle()
        circle.set_color(MAROON_E)
        circle.add_updater(lambda m: set_circle(m))
        self.play(ShowCreation(circle))

        self.wait()

        sub3 = CText('交轴于点Q')\
            .scale(0.3).to_edge(RIGHT)
        self.play(FadeOut(sub2))
        self.play(Write(sub3))

        q = Dot()
        q.set_fill(DARK_BLUE)
        q.plot_depth = 1
        q.add_updater(lambda m:\
            m.move_to(n.get_center() +\
            4 * (focus.get_center() - a.get_center())))
        
        q_label = TexMobject('Q').scale(0.5)
        q_label.plot_depth = 1
        q_label.add_updater(lambda m:\
            m.next_to(q, DR, buff=SMALL_BUFF))
        
        self.play(
            ShowCreation(q),
            ShowCreation(q_label)
        )
        self.wait()

        corollary = VGroup()

        head = CText('推论:').scale(0.25)
        head.set_fill(DARK_BLUE)
        
        crlly = TexMobject('NQ=4AF').scale(0.5)

        head_line = VGroup(head, crlly)
        head_line.arrange(RIGHT)

        proof = VGroup()
        proof_head = CText('证明:').scale(0.25)
        proof_head.set_fill(DARK_BLUE)
        proof.add(proof_head)

        proof_details = VGroup()
        prf1 = CText('在直角三角形AQP1中')\
            .scale(0.25)
        prf2 = TexMobject('P_1N^2=AN\\cdot NQ')\
            .scale(0.5)
        prf3 = VGroup()
        prf3_1 = CText('又').scale(0.25)
        prf3_2 = TexMobject(
            '\\because P_1N^2=4AF\\cdot AN')\
            .scale(0.5)
        prf3.add(prf3_1, prf3_2)
        prf3.arrange(RIGHT, buff=SMALL_BUFF)

        prf4 = TexMobject(
            '\\therefore AN\\cdot NQ=4AF\\cdot AN'
        ).scale(0.5)

        prf5 = TexMobject(
            '\\therefore NQ=4AF'
        ).scale(0.5)

        proof_details.add(prf1, prf2, prf3,
            prf4, prf5)
        proof_details.arrange(DOWN)
        proof.add(proof_details)
        proof.arrange(RIGHT)
        proof_details.align_to(proof_head, UP)
        for e in [prf2, prf3, prf4, prf5]:
            e.align_to(prf1, LEFT)

        corollary.add(head_line)
        corollary.add(proof)
        corollary.arrange(DOWN)
        head_line.align_to(proof, LEFT)
        corollary.to_edge(RIGHT)

        self.play(FadeOut(sub3))
        self.play(ShowCreation(head_line))
        self.play(Write(proof_head))
        self.wait(5)

        self.play(Write(prf1))

        ap1 = DashedLine()
        ap1.add_updater(lambda l:\
            l.put_start_and_end_on(
                a.get_center(), p1.get_center()
            ))

        qp1 = DashedLine()
        qp1.add_updater(lambda l:\
            l.put_start_and_end_on(
                q.get_center(), p1.get_center()
            ))
        self.play(
            ShowCreation(ap1),
            ShowCreation(qp1)
        )
        self.play(ShowCreationThenDestruction(
            Polygon(
                a.get_center(),
                q.get_center(),
                p1.get_center()
            ).set_fill(ORANGE, opacity=1)
        ))
        self.wait(5)
        self.play(Write(prf2))

        self.wait(5)
        self.play(Write(prf3))

        self.wait(3)
        self.play(Write(prf4))
        self.wait(3)
        self.play(Write(prf5))
        self.wait(5)

        self.play(y_val.set_value, 4)
        self.wait(3)
        self.play(y_val.set_value, 2)
        self.wait(10)