Location>code7788 >text

manim learn-by-doing - straight line with arrows

Popularity:450 ℃/2024-09-02 11:57:30

Straight lines with arrowsIt is the directional straight line that can be used to represent both thevector (spatial)It can also be used tomarkingA key position.
manimIt is provided in the4 typesstapleStraight lines with arrowsModule:

  1. Arrow: Straight line with single arrow
  2. DoubleArrow: Straight lines with double arrows
  3. LabeledArrow: Straight lines with labels
  4. Vector: Vector

Among them.DoubleArrowLabeledArrowcap (a poem)VectorAll inherited fromArrowModule.
(indicates contrast)Arrowmodule inherits from the last introducedLineModule.

Vectorfirst glanceArrowSame, also a single arrow straight line, their main difference is:
ArrowRequired settingsbeginningcap (a poem)finishing line (in a race)but (not)VectorJust set thefinishing line (in a race)It'sbeginningsettle fororigin of the coordinate system

Linear series with arrowsThe module is located in themanimhit the nail on the headMobjectUnder.

1. Main parameters

ArrowThe main parameters of the module are:

Parameter name typology clarification
start Point3D beginning
end Point3D finishing line (in a race)
stroke_width float Thickness of arrows
buff float Length of arrows
max_tip_length_to_length_ratio float The ratio of the size of the arrow to the thickness of the line. The larger the value, the larger the arrow is in relation to the line.
max_stroke_width_to_length_ratio float The ratio of the thickness of the line to the size of the arrow; the larger the value, the thicker the line is in relation to the arrow line.
tip_shape VMobject The type of an arrow is, in essence, a geometric object

Among them.startcap (a poem)endThe parameters are inherited fromLineModule.

DoubleArrowThe parameters of the module are the same as those of theArrowIt's basically the same, except it has arrows on both ends.

VectorThe main parameters of the module are:

Parameter name typology clarification
direction Point2D/Point3D The direction of the vector, which corresponds to the end point

VectorThe module only needs to set the endpoint, which isdirection. Other parameters can be found inArrowModule.

module (in software)LabeledArrowA sticky note can be added to a straight line of arrows for adding additional explanatory information.

Parameter name typology clarification
label str Text in tags, can support math formulas
label_position float Label position, default in the middle of the line
font_size float Label font size
label_color Color label color
label_frame bool Whether to show label background
frame_fill_color Color Label background color
frame_fill_opacity float Label background transparency

2. Main approaches

ArrowThe main methods of the module are:

name (of a thing) clarification
get_default_tip_length Get the length of the arrow
get_normal_vector Get the normal of the vector
reset_normal_vector Reset the normals of the vectors
scale scaling vector

DoubleArrowcap (a poem)LabeledArrowmethodology andArrowSame.

VectorIn addition to the aboveArrowmethod, and one that is unique to you:

name (of a thing) clarification
coordinate_label Vector-based coordinates display the value of a vector

For example:

class ArrowExample(Scene):
    def construct(self):
        vec_1 = Vector([1, 3])
        vec_2 = Vector([-2, -2])
        label_1 = vec_1.coordinate_label(color=BLUE)
        label_2 = vec_2.coordinate_label(color=YELLOW)

        (vec_1, vec_2, label_1, label_2)

3. Examples of use

3.1 Proportion of arrows and lines

pass (a bill or inspection etc)buffmax_stroke_width_to_length_ratiocap (a poem)max_tip_length_to_length_ratioparameters.
The proportions of arrows and lines can be adjusted to match the needs of different animation scenes.

# buff
vg = VGroup()
for buff in (0, 2, 0.5):
    (
        Arrow(
            buff=buff,
            start=2 * LEFT,
            end=2 * RIGHT,
        )
    )

(DOWN)
vg.move_to(2.5 * LEFT)
(Create(vg), run_time=run_time)

# max_stroke_width_to_length_ratio
vg = VGroup()
for i in (0, 5, 1):
    (
        Arrow(
            max_stroke_width_to_length_ratio=i,
        ),
    )

(DOWN)
(Create(vg), run_time=run_time)

# max_tip_length_to_length_ratio
vg = VGroup()
for i in (0, 0.3, 0.06):
    (
        Arrow(
            max_tip_length_to_length_ratio=i,
        ),
    )

3.2. Arrow styles

Arrows come in more styles than just triangles.manimThere are a number of different arrow styles built into the

Arrow(
    start=2 * LEFT,
    end=2 * RIGHT,
    tip_shape=ArrowCircleFilledTip,
)
Arrow(
    start=2 * LEFT,
    end=2 * RIGHT,
    tip_shape=ArrowCircleTip,
)
Arrow(
    start=2 * LEFT,
    end=2 * RIGHT,
    tip_shape=ArrowSquareFilledTip,
)
Arrow(
    start=2 * LEFT,
    end=2 * RIGHT,
    tip_shape=ArrowSquareTip,
)
Arrow(
    start=2 * LEFT,
    end=2 * RIGHT,
    tip_shape=ArrowTriangleFilledTip,
)
Arrow(
    start=2 * LEFT,
    end=2 * RIGHT,
    tip_shape=ArrowTriangleTip,
)
Arrow(
    start=2 * LEFT,
    end=2 * RIGHT,
    tip_shape=StealthTip,
)

3.3. Styles of vectors

vectorsIt's a special kind ofstraight line with an arrow, which starts at the coordinate origin by default.
Other properties can be set as above with arrows.

vec1 = Vector([1, 1], color=BLUE)

vec2 = Vector(
    [-2, 1],
    color=RED,
    tip_shape=ArrowSquareTip,
)
label2 = vec2.coordinate_label(color=RED)

vec3 = Vector([2, -1.5], color=GREEN)

3.4 Labeled arrows

Finally.arrowedThe label information can be added to the line, just like a normal line, and is used to describe the line.

LabeledArrow(
    label="y=kx+b",
    font_size=25,
    start=start,
    end=end,
)
LabeledArrow(
    label=txt1,
    start=start,
    end=end,
)
LabeledArrow(
    label="z=\sqrt{x^2+y^2}",
    font_size=25,
    start=start,
    end=end,
    label_color=RED,
    label_frame=False,
)
LabeledArrow(
    label=txt2,
    start=start,
    end=end,
    frame_fill_color=GREEN,
    frame_fill_opacity=0.8,
)

4. Annexes

The complete code for the article is on a web disk (),
Download at.Full Code (Access code: 6872)