表面¶
限定名称: manim.mobject.three\_d.three\_dimensions.Surface
- class Surface(func, u_range=[0, 1], v_range=[0, 1], resolution=32, surface_piece_config={}, fill_color=ManimColor('#29ABCA'), fill_opacity=1.0, checkerboard_colors=[ManimColor('#29ABCA'), ManimColor('#236B8E')], stroke_color=ManimColor('#BBBBBB'), stroke_width=0.5, should_make_jagged=False, pre_function_handle_to_anchor_scale_factor=1e-05, **kwargs)[来源]¶
基础类:
VGroup使用棋盘图案创建一个参数化表面。
- Parameters:
func (Callable[[float, float], np.ndarray]) – 定义
Surface的函数。u_range (Sequence[float]) –
u变量的范围:(u_min, u_max)。v_range (Sequence[float]) –
v变量的范围:(v_min, v_max)。分辨率 (序列[整数]) – 对
Surface进行采样的数量。可以使用元组来分别定义u和v的不同分辨率。fill_color (ParsableManimColor) –
Surface的颜色。如果设置了checkerboard_colors,则忽略此参数。fill_opacity (float) –
Surface的不透明度,从0表示完全透明到1表示完全不透明。默认为1。checkerboard_colors (Sequence[ParsableManimColor] | bool) – 为单个面交替颜色。覆盖
fill_color。stroke_color (ParsableManimColor) –
Surface每个面周围描边的颜色。stroke_width (float) – 围绕
Surface每个面的描边宽度。默认为0.5。should_make_jagged (bool) – 将贝塞尔曲线的锚点模式从平滑更改为锯齿状。 默认为
False。surface_piece_config (字典)
pre_function_handle_to_anchor_scale_factor (float)
kwargs (任意)
示例
示例:ParaSurface ¶
from manim import * class ParaSurface(ThreeDScene): def func(self, u, v): return np.array([np.cos(u) * np.cos(v), np.cos(u) * np.sin(v), u]) def construct(self): axes = ThreeDAxes(x_range=[-4,4], x_length=8) surface = Surface( lambda u, v: axes.c2p(*self.func(u, v)), u_range=[-PI, PI], v_range=[0, TAU], resolution=8, ) self.set_camera_orientation(theta=70 * DEGREES, phi=75 * DEGREES) self.add(axes, surface)
class ParaSurface(ThreeDScene): def func(self, u, v): return np.array([np.cos(u) * np.cos(v), np.cos(u) * np.sin(v), u]) def construct(self): axes = ThreeDAxes(x_range=[-4,4], x_length=8) surface = Surface( lambda u, v: axes.c2p(*self.func(u, v)), u_range=[-PI, PI], v_range=[0, TAU], resolution=8, ) self.set_camera_orientation(theta=70 * DEGREES, phi=75 * DEGREES) self.add(axes, surface)方法
func设置
Surface每个面的填充颜色为交替模式。将参数化曲面的每个mobject的颜色设置为其轴值相关的颜色。
属性
animate用于动画化
self的任何方法的应用。animation_overridescolordepthmobject的深度。
fill_color如果有多种颜色(用于渐变),则返回第一个颜色
heightmobject的高度。
n_points_per_curvesheen_factorstroke_colorwidthmobject的宽度。
- _original__init__(func, u_range=[0, 1], v_range=[0, 1], resolution=32, surface_piece_config={}, fill_color=ManimColor('#29ABCA'), fill_opacity=1.0, checkerboard_colors=[ManimColor('#29ABCA'), ManimColor('#236B8E')], stroke_color=ManimColor('#BBBBBB'), stroke_width=0.5, should_make_jagged=False, pre_function_handle_to_anchor_scale_factor=1e-05, **kwargs)¶
初始化自身。有关准确的签名,请参阅 help(type(self))。
- Parameters:
func (Callable[[float, float], ndarray])
u_range (序列[浮点数])
v_range (序列[浮点数])
分辨率 (序列[整数])
surface_piece_config (字典)
fill_color (ParsableManimColor)
fill_opacity (float)
checkerboard_colors (Sequence[ParsableManimColor] | bool)
stroke_color (ParsableManimColor)
stroke_width (float)
should_make_jagged (bool)
pre_function_handle_to_anchor_scale_factor (float)
kwargs (任意)
- Return type:
无
- set_fill_by_checkerboard(*colors, opacity=None)[来源]¶
设置
Surface每个面的填充颜色为交替模式。- Parameters:
colors (Iterable[ParsableManimColor]) – 用于交替模式的颜色列表。
opacity (float | None) –
Surface的填充不透明度,从0表示完全透明到1表示完全不透明。
- Returns:
具有交替图案的参数化表面。
- Return type:
- set_fill_by_value(axes, colorscale=None, axis=2, **kwargs)[来源]¶
将参数化曲面的每个mobject的颜色设置为其轴值相关的颜色。
- Parameters:
axes (Mobject) – 参数曲面的坐标轴,将用于将轴值映射到颜色。
colorscale (list[ParsableManimColor] | ParsableManimColor | None) – 一个颜色列表,按从低轴值到高轴值的顺序排列。 如果传递了一个包含颜色和数字配对的元组列表, 那么这些数字将被用作枢轴。
axis (int) – 用于颜色映射的选定轴。(0 = x, 1 = y, 2 = z)
- Returns:
应用了基于值的渐变的参数化表面。用于链式操作。
- Return type:
示例
示例:FillByValueExample ¶
from manim import * class FillByValueExample(ThreeDScene): def construct(self): resolution_fa = 8 self.set_camera_orientation(phi=75 * DEGREES, theta=-160 * DEGREES) axes = ThreeDAxes(x_range=(0, 5, 1), y_range=(0, 5, 1), z_range=(-1, 1, 0.5)) def param_surface(u, v): x = u y = v z = np.sin(x) * np.cos(y) return z surface_plane = Surface( lambda u, v: axes.c2p(u, v, param_surface(u, v)), resolution=(resolution_fa, resolution_fa), v_range=[0, 5], u_range=[0, 5], ) surface_plane.set_style(fill_opacity=1) surface_plane.set_fill_by_value(axes=axes, colorscale=[(RED, -0.5), (YELLOW, 0), (GREEN, 0.5)], axis=2) self.add(axes, surface_plane)
class FillByValueExample(ThreeDScene): def construct(self): resolution_fa = 8 self.set_camera_orientation(phi=75 * DEGREES, theta=-160 * DEGREES) axes = ThreeDAxes(x_range=(0, 5, 1), y_range=(0, 5, 1), z_range=(-1, 1, 0.5)) def param_surface(u, v): x = u y = v z = np.sin(x) * np.cos(y) return z surface_plane = Surface( lambda u, v: axes.c2p(u, v, param_surface(u, v)), resolution=(resolution_fa, resolution_fa), v_range=[0, 5], u_range=[0, 5], ) surface_plane.set_style(fill_opacity=1) surface_plane.set_fill_by_value(axes=axes, colorscale=[(RED, -0.5), (YELLOW, 0), (GREEN, 0.5)], axis=2) self.add(axes, surface_plane)