En construccion
from manim import *
import numpy as np
class DerivadaDireccional3D(ThreeDScene):
def construct(self):
# Configurar cámara inicial
self.set_camera_orientation(phi=60 * DEGREES, theta=45 * DEGREES)
# Título
titulo = MathTex(r"\text{Derivada Direccional de } f(x, y) = e^x \cdot \sin(y)", font_size=32).to_edge(UP)
self.add_fixed_in_frame_mobjects(titulo)
# Superficie f(x,y)
superficie = Surface(
lambda u, v: np.array([u, v, np.exp(u) * np.sin(v)]),
u_range=[-2, 2],
v_range=[0, 2 * np.pi],
resolution=(30, 30),
fill_opacity=0.75,
checkerboard_colors=[BLUE_D, BLUE_E]
).scale(0.8).shift(LEFT * 3)
# Ejes
axes = ThreeDAxes(
x_range=[-7, 7, 1],
y_range=[-7, 7, 1],
z_range=[-7, 7, 1],
x_length=6,
y_length=10,
z_length=10,
).scale(0.8).shift(LEFT * 3)
self.play(Create(axes), Create(superficie))
self.wait(1)
# Punto de evaluación
x0, y0 = 0, np.pi / 3
z0 = np.exp(x0) * np.sin(y0)
punto = Dot3D(point=axes.c2p(x0, y0, z0), radius=0.07, color=RED)
punto_label = MathTex(r"P = (0,\ \pi/3,\ f(0,\pi/3))", font_size=28, color=RED).next_to(punto, UP)
self.add(punto, punto_label)
# Gradiente y vector u
df_dx = np.exp(x0) * np.sin(y0)
df_dy = np.exp(x0) * np.cos(y0)
grad = np.array([df_dx, df_dy])
v = np.array([-6, 8])
u = v / np.linalg.norm(v)
deriv_dir = np.dot(grad, u)
escala = 0.7
# Vectores visibles y de colores fuertes
grad_line = Line3D(
start=axes.c2p(x0, y0, z0),
end=axes.c2p(x0 + grad[0]*escala, y0 + grad[1]*escala, z0),
color=RED_E,
thickness=0.05
)
u_line = Line3D(
start=axes.c2p(x0, y0, z0),
end=axes.c2p(x0 + u[0]*escala, y0 + u[1]*escala, z0),
color=YELLOW,
thickness=0.05
)
dx, dy = u * escala
dz = (np.exp(x0 + dx) * np.sin(y0 + dy)) - z0
deriv_line = Line3D(
start=axes.c2p(x0, y0, z0),
end=axes.c2p(x0 + dx, y0 + dy, z0 + dz),
color=BLUE_E,
thickness=0.05
)
# Leyenda
leyenda = VGroup(
MathTex(r"\text{Punto } P", font_size=24, color=RED),
MathTex(r"\nabla f", font_size=24, color=RED_E),
MathTex(r"\vec{u}", font_size=24, color=YELLOW),
MathTex(r"D_{\vec{u}} f", font_size=24, color=BLUE_E)
).arrange(DOWN, aligned_edge=LEFT).to_corner(UR)
# Iniciales JVSR
jvsr_label = Text("JVSR", font_size=20, color=GREEN).to_corner(DL)
self.add_fixed_in_frame_mobjects(jvsr_label, leyenda)
# Mostrar vectores
self.play(Create(grad_line), Create(u_line), Create(deriv_line))
self.wait(2)
# Activar rotación automática de cámara
self.begin_ambient_camera_rotation(rate=0.15)
# Desarrollo simbólico (derecha a izquierda)
desarrollo = [
r"f(x, y) = e^x \sin y \Rightarrow \nabla f(x, y) = \langle e^x \sin y,\ e^x \cos y \rangle",
r"\nabla f(0, \pi/3) = \left\langle \frac{\sqrt{3}}{2},\ \frac{1}{2} \right\rangle",
r"\vec{v} = \langle -6,\ 8 \rangle \Rightarrow \vec{u} = \frac{1}{10} \langle -6,\ 8 \rangle = \left\langle -\frac{3}{5},\ \frac{4}{5} \right\rangle",
r"D_{\vec{u}} f(0, \pi/3) = \left\langle \frac{\sqrt{3}}{2},\ \frac{1}{2} \right\rangle \cdot \left\langle -\frac{3}{5},\ \frac{4}{5} \right\rangle = \frac{4 - 3\sqrt{3}}{10}"
]
for i, tex in enumerate(desarrollo):
linea = MathTex(tex, font_size=28)
linea.to_edge(RIGHT).shift(DOWN * i)
self.play(Write(linea))
self.wait(2)
# Detener rotación al final
self.wait(3)
self.stop_ambient_camera_rotation()