Line3D

完全限定名: manim.mobject.three\_d.three\_dimensions.Line3D

class Line3D(start=array([-1., 0., 0.]), end=array([1., 0., 0.]), thickness=0.02, color=None, resolution=24, **kwargs)[源码]

继承自: Cylinder

用于ThreeDScene的圆柱形线。

参数:
  • **start** (*np.ndarray*) – 线的起点。

  • **end** (*np.ndarray*) – 线的终点。

  • **thickness** (*float*) – 线的厚度。

  • **color** (ParsableManimColor | None) – 线的颜色。

  • **resolution** (*int* | Sequence[int]) – 线的解析度。默认情况下,此值为线将采样的点数。如果你想让线也显示为棋盘格状,请使用元组。例如,对于由24个点组成的线,每个圆柱上有4个棋盘格点,则传入元组 (4, 24)。

示例

示例: ExampleLine3D

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

class ExampleLine3D(ThreeDScene):
    def construct(self):
        axes = ThreeDAxes()
        line = Line3D(start=np.array([0, 0, 0]), end=np.array([2, 2, 2]))
        self.set_camera_orientation(phi=75 * DEGREES, theta=30 * DEGREES)
        self.add(axes, line)
class ExampleLine3D(ThreeDScene):
    def construct(self):
        axes = ThreeDAxes()
        line = Line3D(start=np.array([0, 0, 0]), end=np.array([2, 2, 2]))
        self.set_camera_orientation(phi=75 * DEGREES, theta=30 * DEGREES)
        self.add(axes, line)

方法

获取终点

返回 Line3D 的终点。

获取起点

返回 Line3D 的起点。

parallel_to

返回一条平行于另一条线并穿过给定点的线。

perpendicular_to

返回一条垂直于另一条线并穿过给定点的线。

pointify

获取一个点,表示 Mobjects 的中心。

set_start_and_end_attrs

设置线的起点和终点。

属性

animate (动画)

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

animation_overrides (动画覆盖)

颜色

depth (深度)

mobject 的深度。

fill_color (填充颜色)

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

height (高度)

mobject 的高度。

n_points_per_curve (每条曲线的点数)

sheen_factor (光泽因子)

stroke_color (描边颜色)

width (宽度)

mobject 的宽度。

_original__init__(start=array([-1., 0., 0.]), end=array([1., 0., 0.]), thickness=0.02, color=None, resolution=24, **kwargs)

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

参数:
  • **start** (*np.ndarray*)

  • **end** (*np.ndarray*)

  • **thickness** (*float*)

  • **color** (ParsableManimColor | None)

  • **resolution** (*int* | Sequence[int])

get_end()[源码]

返回 Line3D 的终点。

返回:

**end** – Line3D 的终点。

返回类型:

numpy.array

get_start()[源码]

返回 Line3D 的起点。

返回:

**start** – Line3D 的起点。

返回类型:

numpy.array

classmethod parallel_to(line, point=array([0., 0., 0.]), length=5, **kwargs)[源码]

返回一条平行于另一条线并穿过给定点的线。

参数:
  • **line** (Line3D) – 要平行的线。

  • **point** (Vector3D) – 要穿过的点。

  • **length** (*float*) – 平行线的长度。

  • **kwargs** – 传递给类的其他参数。

返回:

平行于 line 的线。

返回类型:

三维线

示例

示例: ParallelLineExample

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

class ParallelLineExample(ThreeDScene):
    def construct(self):
        self.set_camera_orientation(PI / 3, -PI / 4)
        ax = ThreeDAxes((-5, 5), (-5, 5), (-5, 5), 10, 10, 10)
        line1 = Line3D(RIGHT * 2, UP + OUT, color=RED)
        line2 = Line3D.parallel_to(line1, color=YELLOW)
        self.add(ax, line1, line2)
class ParallelLineExample(ThreeDScene):
    def construct(self):
        self.set_camera_orientation(PI / 3, -PI / 4)
        ax = ThreeDAxes((-5, 5), (-5, 5), (-5, 5), 10, 10, 10)
        line1 = Line3D(RIGHT * 2, UP + OUT, color=RED)
        line2 = Line3D.parallel_to(line1, color=YELLOW)
        self.add(ax, line1, line2)

classmethod perpendicular_to(line, point=array([0., 0., 0.]), length=5, **kwargs)[源码]

返回一条垂直于另一条线并穿过给定点的线。

参数:
  • **line** (Line3D) – 要垂直于的线。

  • **point** (Vector3D) – 要穿过的点。

  • **length** (*float*) – 垂直线的长度。

  • **kwargs** – 传递给类的其他参数。

返回:

垂直于 line 的线。

返回类型:

三维线

示例

示例: PerpLineExample

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

class PerpLineExample(ThreeDScene):
    def construct(self):
        self.set_camera_orientation(PI / 3, -PI / 4)
        ax = ThreeDAxes((-5, 5), (-5, 5), (-5, 5), 10, 10, 10)
        line1 = Line3D(RIGHT * 2, UP + OUT, color=RED)
        line2 = Line3D.perpendicular_to(line1, color=BLUE)
        self.add(ax, line1, line2)
class PerpLineExample(ThreeDScene):
    def construct(self):
        self.set_camera_orientation(PI / 3, -PI / 4)
        ax = ThreeDAxes((-5, 5), (-5, 5), (-5, 5), 10, 10, 10)
        line1 = Line3D(RIGHT * 2, UP + OUT, color=RED)
        line2 = Line3D.perpendicular_to(line1, color=BLUE)
        self.add(ax, line1, line2)

pointify(mob_or_point, direction=None)[源码]

获取一个点,表示 Mobjects 的中心。

参数:
返回:

Mobjects 的中心或点,如果给定方向则为边。

返回类型:

numpy.array

set_start_and_end_attrs(start, end, **kwargs)[源码]

设置线的起点和终点。

如果 startendMobjects,则此函数返回它们的中心。

参数:
  • **start** (*ndarray*) – 起点或 Mobject

  • **end** (*ndarray*) – 终点或 Mobject

返回类型: