ParametricFunction

完整名称: manim.mobject.graphing.functions.ParametricFunction

class ParametricFunction(function, t_range=(0, 1), scaling=<manim.mobject.graphing.scale.LinearBase object>, dt=1e-08, discontinuities=None, use_smoothing=True, use_vectorized=False, **kwargs)[source]

基类: VMobject

一条参数曲线。

参数:
  • function (Callable[[float], Point3DLike]) – 要绘制的函数,形式为 (lambda t: (x(t), y(t), z(t)))

  • t_range (tuple[float, float] | tuple[float, float, float]) – 决定函数跨度,形式为 (t_min, t_max, step=0.01)。默认值为 [0, 1]

  • scaling (_ScaleBase) – 应用于函数点的缩放类。默认为 LinearBase

  • use_smoothing (bool) – 是否在点生成后对其进行插值。(点数量较少时可能会有奇怪的行为)

  • use_vectorized (bool) – 是否将生成的 t 值数组作为 [t_0, t_1, ...] 传递给函数。仅在您的函数支持此功能时使用。输出应为形状为 [[x_0, x_1, ...], [y_0, y_1, ...], [z_0, z_1, ...]] 的 numpy 数组,但如果 Axes 为 2D,则 z 也可以为 0。

  • discontinuities (Iterable[float] | None) – 函数发生不连续的 t 值。

  • dt (float) – 不连续点的左右容差。

示例

示例: PlotParametricFunction

../_images/PlotParametricFunction-1.png
from manim import *

class PlotParametricFunction(Scene):
    def func(self, t):
        return (np.sin(2 * t), np.sin(3 * t), 0)

    def construct(self):
        func = ParametricFunction(self.func, t_range = (0, TAU), fill_opacity=0).set_color(RED)
        self.add(func.scale(3))
class PlotParametricFunction(Scene):
    def func(self, t):
        return (np.sin(2 * t), np.sin(3 * t), 0)

    def construct(self):
        func = ParametricFunction(self.func, t_range = (0, TAU), fill_opacity=0).set_color(RED)
        self.add(func.scale(3))

示例: ThreeDParametricSpring

../_images/ThreeDParametricSpring-1.png
from manim import *

class ThreeDParametricSpring(ThreeDScene):
    def construct(self):
        curve1 = ParametricFunction(
            lambda u: (
                1.2 * np.cos(u),
                1.2 * np.sin(u),
                u * 0.05
            ), color=RED, t_range = (-3*TAU, 5*TAU, 0.01)
        ).set_shade_in_3d(True)
        axes = ThreeDAxes()
        self.add(axes, curve1)
        self.set_camera_orientation(phi=80 * DEGREES, theta=-60 * DEGREES)
        self.wait()
class ThreeDParametricSpring(ThreeDScene):
    def construct(self):
        curve1 = ParametricFunction(
            lambda u: (
                1.2 * np.cos(u),
                1.2 * np.sin(u),
                u * 0.05
            ), color=RED, t_range = (-3*TAU, 5*TAU, 0.01)
        ).set_shade_in_3d(True)
        axes = ThreeDAxes()
        self.add(axes, curve1)
        self.set_camera_orientation(phi=80 * DEGREES, theta=-60 * DEGREES)
        self.wait()

注意

如果您的函数存在不连续性,您需要手动指定不连续性的位置。请参阅以下示例以获取指导。

示例: DiscontinuousExample

../_images/DiscontinuousExample-1.png
from manim import *

class DiscontinuousExample(Scene):
    def construct(self):
        ax1 = NumberPlane((-3, 3), (-4, 4))
        ax2 = NumberPlane((-3, 3), (-4, 4))
        VGroup(ax1, ax2).arrange()
        discontinuous_function = lambda x: (x ** 2 - 2) / (x ** 2 - 4)
        incorrect = ax1.plot(discontinuous_function, color=RED)
        correct = ax2.plot(
            discontinuous_function,
            discontinuities=[-2, 2],  # discontinuous points
            dt=0.1,  # left and right tolerance of discontinuity
            color=GREEN,
        )
        self.add(ax1, ax2, incorrect, correct)
class DiscontinuousExample(Scene):
    def construct(self):
        ax1 = NumberPlane((-3, 3), (-4, 4))
        ax2 = NumberPlane((-3, 3), (-4, 4))
        VGroup(ax1, ax2).arrange()
        discontinuous_function = lambda x: (x ** 2 - 2) / (x ** 2 - 4)
        incorrect = ax1.plot(discontinuous_function, color=RED)
        correct = ax2.plot(
            discontinuous_function,
            discontinuities=[-2, 2],  # discontinuous points
            dt=0.1,  # left and right tolerance of discontinuity
            color=GREEN,
        )
        self.add(ax1, ax2, incorrect, correct)

方法

generate_points (生成点)

初始化 points,从而确定形状。

get_function

get_point_from_function

init_points (初始化点)

初始化 points,从而确定形状。

属性

animate (动画)

用于动画化 self 的任何方法的应用。

animation_overrides (动画覆盖)

颜色

depth (深度)

mobject 的深度。

fill_color (填充颜色)

如果存在多种颜色(用于渐变),则返回第一种颜色

height (高度)

mobject 的高度。

n_points_per_curve (每条曲线的点数)

sheen_factor (光泽因子)

stroke_color (描边颜色)

width (宽度)

mobject 的宽度。

_original__init__(function, t_range=(0, 1), scaling=<manim.mobject.graphing.scale.LinearBase object>, dt=1e-08, discontinuities=None, use_smoothing=True, use_vectorized=False, **kwargs)

初始化自身。有关准确签名,请参阅 help(type(self))。

参数:
  • function (Callable[[float], Point3DLike])

  • t_range (tuple[float, float] | tuple[float, float, float])

  • scaling (_ScaleBase)

  • dt (float)

  • discontinuities (Iterable[float] | None)

  • use_smoothing (bool)

  • use_vectorized (bool)

generate_points()[source]

初始化 points,从而确定形状。

在创建时调用。这是一个空方法,可由子类实现。

返回类型:

自身

init_points()

初始化 points,从而确定形状。

在创建时调用。这是一个空方法,可由子类实现。

返回类型:

自身