I checked manim's method. I tried using ParametricSurface.
from manimlib.imports import *
class DSurface(ParametricSurface):
def __init__(self, **kwargs):
kwargs = {
"u_min": -1.5,
"u_max": 1.5,
"v_min": -1.5,
"v_max": 1.5,
"checkerboard_colors": [GREEN, BLUE],
"checkerboard_opacity": 0.5
}
ParametricSurface.__init__(self, self.func, **kwargs)
def func(self, x, y):
return np.array([x, y, x ** 2 + y ** 2])
class test(ThreeDScene):
def construct(self):
sphere = ParametricSurface(lambda u, v: np.array([1.5 * np.cos(u) * np.cos(v), 1.5 * np.cos(u) * np.sin(v), 1.5 * np.sin(u)]), v_min = 0, v_max = TAU, u_min = -PI / 2, u_max = PI / 2, checkerboard_colors = [RED_D, RED_E], resolution = (15, 32))
def param_plane(u, v):
x = u
y = v
z = 0
return np.array([x, y, z])
plane = ParametricSurface(param_plane, resolution = (22, 22), v_min = -2, v_max = +2, u_min = -2, u_max = +2, )
def param_gauss(u, v):
x = u
y = v
d = np.sqrt(x * x + y * y)
sigma, mu = 0.4, 0.0
z = np.exp(-((d - mu) ** 2 / (2.0 * sigma ** 2)))
return np.array([x, y, z])
gauss_plane = ParametricSurface(param_gauss, resolution = (22, 22), v_min = -2, v_max = +2, u_min = -2, u_max = +2, )
cylinder = ParametricSurface(lambda u, v: np.array([np.cos(TAU * v), np.sin(TAU * v), 1.0 * (1 - u)]), resolution = (6, 32))
surface = DSurface()
axes = ThreeDAxes()
self.set_camera_orientation(phi = 75 * DEGREES, theta = 30 * DEGREES)
self.add(axes)
self.play(ShowCreation(sphere))
self.wait()
self.remove(sphere)
self.play(ShowCreation(plane))
self.wait()
self.remove(plane)
self.play(ShowCreation(gauss_plane))
self.wait()
self.remove(gauss_plane)
self.play(ShowCreation(cylinder))
self.wait()
self.remove(cylinder)
self.play(ShowCreation(surface))
self.wait()
https://www.youtube.com/watch?v=HATdDHmnmD8
that's all.
Recommended Posts