Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Cavalerie(ThreeDScene):
- def construct(self):
- mob_1 = SVGMobject(
- 'mob_1.svg', height=4
- ).set_stroke(WHITE).set_fill(TEAL).shift(2 * RIGHT).set_z_index(2)
- mob_2 = SVGMobject(
- 'mob_2.svg', height=4
- ).set_stroke(WHITE).set_fill(TEAL).shift(2 * LEFT + 2 * IN).set_z_index(2)
- self.add_fixed_orientation_mobjects(mob_1, mob_2)
- area = Polygon(
- [5, 5, -3], [5, -5, -3], [-5, -5, -3], [-5, 5, -3]
- ).set_fill(YELLOW, 0.2).set_stroke(opacity=0).set_z_index(-2)
- # area = Polygon(
- # [5, 0, 0], [3, -3, 0], [-6, -3, 0], [-4, 0, 0]
- # ).set_fill(YELLOW, 0.2).set_stroke(opacity=0).set_z_index(-2)
- area_2 = area.copy()
- un = always_redraw(lambda:
- Intersection(area_2, mob_1, color=GREEN, fill_opacity=1)
- )
- pM = always_redraw(lambda:
- Dot(un.get_center()).set_fill(YELLOW)
- )
- self.set_camera_orientation(
- phi = 75 * DEGREES,
- theta = 30 * DEGREES,
- focal_distance=500
- )
- self.add(mob_1, mob_2, area, area_2, un, pM)
- self.play(area_2.animate.shift(4 * OUT), run_time=7)
- class Hyperboloid(ThreeDScene):
- def construct(self):
- axes = ThreeDAxes(x_range=[-3, 3], y_range=[-3, 3], z_range=[-3, 3])
- # функции
- vertex_coords = [
- [2, 2, 0],
- [2, -2, 0],
- [-2, -2, 0],
- [-2, 2, 0],
- [0, 0, 4]
- ]
- faces_list = [
- [0, 1, 4],
- [1, 2, 4],
- [2, 3, 4],
- [3, 0, 4],
- [0, 1, 2, 3]
- ]
- pyramid = Polyhedron(
- vertex_coords, faces_list
- ).move_to(2 * UL + 1 * IN).set_fill(opacity = 0.5)
- # конус
- h = 4
- r = 2
- cone_surface = Surface(
- lambda u, v: np.array([v * r * np.cos(u), v * r * np.sin(u), (1 - v) * h]),
- u_range=(0, 2 * PI),
- v_range=(0, 1),
- resolution=(16, 32),
- color=BLUE,
- ).shift(2 * DR + 2 * IN).set_fill(opacity = 0.5)
- # плоскость
- area = Rectangle(
- height = 15, width = 10
- ).shift([0, 0, -2]).set_stroke(YELLOW, 1).set_fill(YELLOW, 0.1)
- # анимации
- self.set_camera_orientation(
- phi=75 * DEGREES,
- theta=45 * DEGREES
- )
- self.add(cone_surface, pyramid, area)
- self.wait()
- self.play(area.animate.shift([0, 0, 3]), run_time = 4)
- self.wait()
- class IntersectionExample(ThreeDScene):
- def construct(self):
- def param_surface(u, v):
- x = u
- y = v
- z = 0
- return np.array([x, y, z])
- # Parameters for the cone
- radius = 1
- height = 2
- # Create the cone
- cone = Surface(
- lambda u, v: np.array([
- radius * v * np.cos(u),
- radius * v * np.sin(u),
- height * (1 - v)
- ]),
- u_range=[0, 2 * PI],
- v_range=[0, 1],
- resolution=(20, 20),
- ).set_color(BLUE).set_opacity(0.3)
- # Create the plane
- plane = Rectangle().shift(OUT).set_color(TEAL, 0.6).set_fill(TEAL, 0.6)
- # plane = Surface(
- # param_surface,
- # u_range=[0, 2 * PI],
- # v_range=[0, 1],
- # resolution=(20, 20),
- # ).shift(OUT).set_color(TEAL, 0.6).set_fill(TEAL, 0.6)
- inter = Intersection(
- plane,
- cone,
- fill_color = GREEN,
- fill_opacity = 1,
- stroke_color = GREEN,
- stroke_opacity = 1
- )
- self.set_camera_orientation(phi=75 * DEGREES, theta=45 * DEGREES)
- self.add(cone, plane, inter)
- self.wait()
- self.play(plane.animate.shift([0, 0, 3]), run_time = 4)
- # self.move_camera(
- # phi=75 * DEGREES,
- # theta=375 * DEGREES,
- # run_time = 10
- # )
- class IntersectionScene(ThreeDScene):
- def construct(self):
- # Задаем поверхность второго порядка
- radius = 1
- height = 2
- surface = Surface(
- lambda u, v: np.array([
- radius * v * np.cos(u),
- radius * v * np.sin(u),
- height * (1 - v)
- ]),
- u_range=[0, 2 * PI],
- v_range=[0, 1],
- resolution=(20, 20),
- ).set_color(TEAL, 0.6).set_fill(TEAL, 0.6)
- z = ValueTracker()
- # Задаем плоскость
- plane = always_redraw(lambda:
- Surface(
- lambda u, v: np.array([u, v, z.get_value()]),
- u_range=[-2, 2],
- v_range=[-2, 2],
- resolution=(20, 20),
- ).set_color(YELLOW, 0.6).set_fill(YELLOW, 0.6)
- )
- plane = Surface(
- lambda u, v: np.array([u, v, z.get_value()]),
- u_range=[-2, 2],
- v_range=[-2, 2],
- resolution=(20, 20),
- ).set_color(YELLOW, 0.6).set_fill(YELLOW, 0.6)
- # Находим пересечение
- intersection = always_redraw(lambda:
- Intersection(
- surface, plane,
- fill_color = GREEN,
- fill_opacity = 1,
- stroke_color = GREEN,
- stroke_opacity = 1
- )
- )
- self.set_camera_orientation(phi=75 * DEGREES, theta=45 * DEGREES)
- self.add(surface, plane, intersection)
- self.wait()
- self.play(z.animate.set_value(2), run_time = 4)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement