Image

¿Cómo crear Superficies con Manim?

Crear superficies y animarlas en Manim, rotaciones y cambio de perspectivas.

from manim import *

class Escena1(ThreeDScene):
    def construct(self):
        cielo = "#C4DDFF"
        azul = "#001D6E"
        rojo = "#B20600"
        BLACK="#000000"
        self.camera.background_color = cielo
        axes = ThreeDAxes().set_color(azul)
        x=MathTex("x", color=azul).move_to(np.array([5,0.5,0]))
        y=MathTex("y", color=azul).move_to(np.array([0.5,5,0]))
        self.set_camera_orientation(phi=65 * DEGREES, theta=60 * DEGREES)
        self.add(axes,x,y)
        text3d = MathTex("z=(x^2+3y^2)e^{1-x^2-y^2}", color=BLACK).to_corner(UL)
        self.add_fixed_in_frame_mobjects(text3d)

        curva = Surface(lambda u, v: np.array([u, v, (u ** 2 + 3 * v ** 2) * np.exp(1 - u ** 2 - v ** 2)]),
                        v_range=[-3, 3],
                        u_range=[-3, 3],
                        checkerboard_colors=[RED_D, RED_E],
                        resolution=(15, 32))
        curva.set_fill_by_checkerboard(rojo, azul, opacity=0.5)
        self.play(Write(curva))
        self.wait(5)
        text1 = MathTex("\theta\leftarrow", "0^\circ ", color=BLACK).move_to(RIGHT * 5.3 + UP * 3)
        text2 = MathTex("\phi\leftarrow", "0^\circ ", color=BLACK).move_to(RIGHT * 5.3 + UP * 1.7)
        self.add_fixed_in_frame_mobjects(text1, text2)
        self.move_camera(theta=0, phi=0)
        self.wait(5)

        text3 = MathTex("\theta \leftarrow", "0^\circ", color=BLACK).move_to(RIGHT * 5.3 + UP * 3)
        text4 = MathTex("\phi \leftarrow ", "{45}^\circ", color=BLACK).move_to(RIGHT * 5.3 + UP * 1.7)
        self.play(FadeOut(text1[1], text2[1]))
        self.add_fixed_in_frame_mobjects(text3[1], text4[1])
        self.move_camera(theta=0, phi=PI / 4)
        self.wait(5)

        text5 = MathTex("\theta \leftarrow ", " 0^\circ", color=BLACK).move_to(RIGHT * 5.3 + UP * 3)
        text6 = MathTex("\phi \leftarrow ", "{90}^\circ", color=BLACK).move_to(RIGHT * 5.3 + UP * 1.7)
        self.play(FadeOut(text3[1], text4[1]))
        self.add_fixed_in_frame_mobjects(text5[1], text6[1])
        self.move_camera(theta=0, phi=PI / 2)
        self.wait(5)

        text7 = MathTex("\theta \leftarrow ", "{45}^\circ", color=BLACK).move_to(RIGHT * 5.3 + UP * 3)
        text8 = MathTex("\phi  \leftarrow ", "{90}^\circ", color=BLACK).move_to(RIGHT * 5.3 + UP * 1.7)
        self.play(FadeOut(text5[1], text6[1]))
        self.add_fixed_in_frame_mobjects(text7[1], text8[1])
        self.move_camera(theta=PI / 4, phi=PI / 2, )

        self.wait(5)

        text9 = MathTex("\theta \leftarrow ", "{45}^\circ", color=BLACK).move_to(RIGHT * 5.3 + UP * 3)
        text10 = MathTex("\phi \leftarrow ", "{60}^\circ", color=BLACK).move_to(RIGHT * 5.3 + UP * 1.7)
        self.play(FadeOut(text7[1], text8[1]))
        self.add_fixed_in_frame_mobjects(text9[1], text10[1])
        self.move_camera(theta=PI / 4, phi=PI / 3)
        self.wait(5)

        self.begin_ambient_camera_rotation(rate=0.10)
        self.wait(8)

© Profesor Favián Arenas. 2023. Diseñado por HTML Codex