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.manim
It is provided in the4 typesstapleStraight lines with arrowsModule:
-
Arrow
: Straight line with single arrow -
DoubleArrow
: Straight lines with double arrows -
LabeledArrow
: Straight lines with labels -
Vector
: Vector
Among them.DoubleArrow
,LabeledArrow
cap (a poem)Vector
All inherited fromArrow
Module.
(indicates contrast)Arrow
module inherits from the last introducedLine
Module.
Vector
first glanceArrow
Same, also a single arrow straight line, their main difference is:Arrow
Required settingsbeginningcap (a poem)finishing line (in a race)but (not)Vector
Just set thefinishing line (in a race)It'sbeginningsettle fororigin of the coordinate system。
Linear series with arrowsThe module is located in themanim
hit the nail on the headMobject
Under.
1. Main parameters
Arrow
The 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.start
cap (a poem)end
The parameters are inherited fromLine
Module.
DoubleArrow
The parameters of the module are the same as those of theArrow
It's basically the same, except it has arrows on both ends.
Vector
The main parameters of the module are:
Parameter name | typology | clarification |
---|---|---|
direction | Point2D/Point3D | The direction of the vector, which corresponds to the end point |
Vector
The module only needs to set the endpoint, which isdirection
. Other parameters can be found inArrow
Module.
module (in software)LabeledArrow
A 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
Arrow
The 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 |
DoubleArrow
cap (a poem)LabeledArrow
methodology andArrow
Same.
Vector
In addition to the aboveArrow
method, 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)buff
,max_stroke_width_to_length_ratio
cap (a poem)max_tip_length_to_length_ratio
parameters.
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.manim
There 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)