Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ConicSection(ThreeDScene):
- def construct(self):
- # Заголовки
- Text.set_default(font = 'TT Firs Neue')
- h1 = Text('Поговорим про объемы', color = YELLOW).scale(0.8).to_edge(UL, buff=0.5)
- h2 = Text(
- "Принцип Кавальери"
- ).scale(0.65).next_to(h1, DOWN, aligned_edge=LEFT, buff = 0.3)
- self.add_fixed_in_frame_mobjects(h1, h2)
- self.remove(h2)
- # конус
- r = 2 # высота и радиус основания конуса
- cone = Cone(r, r).set_fill(BLUE, 1)
- cone.next_to(ORIGIN, OUT, buff=0).shift(2.5 * DOWN)
- #
- plane = Square(2 * r + 1).set_fill(TEAL, 0).set_stroke(opacity = 0).shift(2.5 * DOWN)
- circle = Circle(r).set_stroke(YELLOW, 3).set_fill(YELLOW, 0.2).shift(2.5 * DOWN)
- area_circ = circle.copy()
- area_circ.to_edge(DL)
- tex_c = always_redraw(lambda:
- MathTex("S_1").move_to(circle.get_center()).add_background_rectangle(color = BLACK)
- )
- self.add_fixed_in_frame_mobjects(area_circ, tex_c)
- self.remove(area_circ, tex_c)
- def upd_circle(circ):
- height = plane.get_center()[2]
- circ.move_to(height * OUT + 2.5 * DOWN)
- new_radius = r - height
- circ.set(width=2*new_radius)
- def upd_area_circ(circ):
- height = plane.get_center()[2]
- circ.to_edge(DL)
- new_radius = r - height
- circ.set(width=2*new_radius)
- circle.add_updater(upd_circle)
- area_circ.add_updater(upd_area_circ)
- # пирамида
- h = np.sqrt(4 * PI)/2
- c = Dot(radius=0.00001).move_to(plane.get_center()[2])
- vertex_coords = [
- [r, r, c.get_center()[2]],
- [r, -r, c.get_center()[2]],
- [-r, -r, c.get_center()[2]],
- [-r, r, c.get_center()[2]],
- [0, 0, 2]
- ]
- faces_list = [
- [0, 1, 4],
- [1, 2, 4],
- [2, 3, 4],
- [3, 0, 4],
- [0, 1, 2, 3]
- ]
- pyramid = Polyhedron(
- vertex_coords, faces_list
- ).next_to(ORIGIN, OUT, buff=0).set_stroke(WHITE, 2.5).shift(2.5 * UP)
- pyramid.graph.set_opacity(0)
- plane_2 = Square(
- 4 * h + 1
- ).set_fill(TEAL, 0).next_to(c.get_center()[2], OUT, buff=0).set_stroke(opacity = 0)
- square = Square(
- 2 * r
- ).set_stroke(PURPLE_A, 3).set_fill(PURPLE_A, 0.2).next_to(c.get_center()[2], OUT, buff=0).shift(0.1 * OUT + 2.5 * UP)
- cons = MathTex("=").next_to(area_circ, RIGHT, buff = 0.2)
- cons.add_updater(lambda obj: obj.next_to(area_circ, RIGHT, buff = 0.2))
- self.add_fixed_in_frame_mobjects(cons)
- self.remove(cons)
- area_squar = square.copy()
- area_squar.next_to(cons, RIGHT, buff = 0.2)
- tex_c2 = MathTex("S_2").move_to(square.get_center()).add_background_rectangle(color = BLACK)
- self.add_fixed_in_frame_mobjects(area_squar, tex_c, tex_c2)
- self.remove(area_squar, tex_c, tex_c2)
- tex_c2.add_updater(lambda obj: obj.move_to(area_squar.get_center()))
- # апдейтеры
- def upd_square(squar):
- height = plane_2.get_center()[2]
- squar.move_to(height * OUT + 2.5 * UP)
- new_lenght = r - height
- squar.set(width = 2 * new_lenght).shift(0.1 * OUT)
- def upd_area_square(squar):
- height = plane_2.get_center()[2]
- squar.next_to(cons, RIGHT, buff = 0.2)
- new_lenght = r - height
- squar.set(width = 2 * new_lenght).shift(0.1 * OUT)
- square.add_updater(upd_square)
- area_squar.add_updater(upd_area_square)
- big_plane = Rectangle(
- height = 12, width = 8
- ).set_fill(TEAL, 0.4).set_stroke(TEAL_A, 0).move_to(plane.get_center() + 3 * UP)
- # камера
- self.set_camera_orientation(
- phi= 70 * DEGREES,
- theta = 20 * DEGREES,
- zoom = 0.9
- )
- # анимации
- self.play(FadeIn(h2, shift = RIGHT))
- self.wait()
- self.play(FadeIn(cone, shift = OUT), FadeIn(pyramid, shift = OUT), run_time = 2)
- self.add(c, plane, plane_2)
- self.wait()
- self.play(Create(big_plane), Create(circle), Create(square), run_time = 3)
- self.wait()
- self.play(Write(tex_c), Write(tex_c2))
- # self.play(FadeIn(area_circ), FadeIn(cons), FadeIn(area_squar), Write(tex_c), Write(tex_c2))
- self.wait()
- self.play(
- plane.animate.shift(0.6 * OUT),
- plane_2.animate.shift(0.6 * OUT),
- big_plane.animate.shift(0.6 * OUT),
- run_time=5
- )
- self.wait()
- self.play(
- plane.animate.shift(0.6 * OUT),
- plane_2.animate.shift(0.6 * OUT),
- big_plane.animate.shift(0.6 * OUT),
- run_time=6
- )
- self.wait()
- self.play(
- plane.animate.shift(0.5 * OUT),
- plane_2.animate.shift(0.5 * OUT),
- big_plane.animate.shift(0.5 * OUT),
- run_time=7
- )
- self.wait()
- # выыод
- conclusion = MathTex(
- r"\Rightarrow", "V_1 = V_2"
- ).next_to(area_squar, RIGHT, buff = 0.2)
- self.add_fixed_in_frame_mobjects(conclusion)
- self.remove(conclusion)
- self.play(Write(conclusion), run_time = 2.5)
- self.wait()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement