manim
Drawing an angle in this article is actually drawing two straight lines, and this article is not about drawing angles, but drawingangle mark。
insofar asacute anglecap (a poem)obtuse angle,angle markis an arc, and the degree of an arc is the same as the degree of an angle;
insofar asa right angle,angle markIt's a vertical corner.
manim
consultations onangle markThere are 3 main models of the
-
Angle
: Draw angle markers based on two straight lines -
RightAngle
: Under both articlesmutually perpendicularThe right angle markers are drawn on the lines of the -
Elbow
: Right angle markings in any direction and size, not limited to straight lines
Among them.RightAngle
Modules inherited fromAngle
。
angle markThe main purpose of this is to mark some special angles in the animation to better show the process of proving mathematical theorems.
1. Main parameters
Angle
Modules are universal angle markers, which have the main parameters:
Parameter name | typology | clarification |
---|---|---|
line1 | Line | The first line that forms an angle |
line2 | Line | The second line that forms the angle |
radius | float | Radius of Angle Marker |
quadrant | Point2D | This parameter controls where the angle markers are displayed |
other_angle | bool |
True : Clockwise from line1 to line2False : Counterclockwise from line1 to line2 |
dot | bool | Whether to show a point in the angle marker |
dot_radius | float | radius of a point |
dot_distance | float | Relative distance from point to arc (angle marker) |
dot_color | Color | Dot color |
elbow | bool | Whether to display the shape at right angles |
The use of these parameters is demonstrated later in the usage examples.
RightAngle
Modules inherited fromAngle
In addition to the aboveAngle
has a parameter specific to itself in addition to the parameter of the
Parameter name | typology | clarification |
---|---|---|
length | float | Size of markers |
Elbow
module is different from the above two in that it does not generate angle markers based on two lines.
Parameter name | typology | clarification |
---|---|---|
width | float | Size of markers |
angle | float | The marker is facing that direction. |
Elbow
shape andRightAngle
It's the same.
2. Main approaches
Angle
There are 3 main approaches to modules:
name (of a thing) | clarification |
---|---|
from_three_points | Generate angle markers based on three points |
get_lines | Get the two lines that generate the angle |
get_value | Get the value of the angle |
Usually when I draw an angle marker, I base the angle position on two intersecting lines.
pass (a bill or inspection etc)from_three_points
method, which can generate an angle marker based on any 3 points.
A = ([2, -1, 0])
B = ([0, 0, 0])
C = ([1, 1, 0])
angle = Angle.from_three_points(A, B, C)
The parameters of the function areA
,B
,C
Three points.
- A: Starting point of the angle
- B: Vertex of the angle
- C: The end of the angle
The generated angles are expressed in terms ofB
as the vertex and rotate counterclockwise from point A to point C.
methodologiesget_lines
The two lines that make up the angle can be obtained, i.e., in the figure aboveBA
,BC
Two lines.
lines = angle.get_lines()
Finally.get_value
method to get the value of the current angle in real time, the value can be in degrees or radians.
print(f "angle: {angle.get_value(degrees=True)}")
print(f "radians: {angle.get_value()}")
# Run the result
Angle: 71.56505117707799
Radian: 1.2490457723982544
3. Examples of use
3.1 Angle size
Because the angle markersAngle
is an arc, so the size of the angle is determined by the parameterradius
(radius) to adjust.
line1 = Line(LEFT, RIGHT)
line2 = Line(DOWN, UP)
Angle(line1, line2)
Angle(line1, line2, radius=0.2)
Angle(line1, line2, radius=0.5)
Angle(line1, line2, radius=0.8)
3.2 Angular position
The position of the angle markers is controlled by two parameters, thequadrant
cap (a poem)other_angle
。
quadrant
There are a total of four options for the parameter:(1, 1)
maybe(1, -1)
maybe(-1, 1)
maybe(-1, -1)
This parameter is divided into two parts, which represent the angle markers in theLine1
upperstarting pointand inLine2
upperfinishing position。
For example, the following two lines that intersectquadrant
The first and second values of theLine1
cap (a poem)Line2
The position on it is shown in the figure.
other_angle
defaultFalse
, indicating that the angle is drawn fromLine1
until (a time)Line2
;
set upother_angle
is True, the angles are drawn in the opposite order, fromLine2
until (a time)Line1
。
l1 = Line(
LEFT + (1 / 3) * UP,
RIGHT + (1 / 3) * DOWN,
)
l2 = Line(
DOWN + (1 / 3) * RIGHT,
UP + (1 / 3) * LEFT,
)
Angle(l1, l2)
Angle(l1, l2, quadrant=(1, -1))
Angle(l1, l2, quadrant=(-1, 1))
Angle(l1, l2, quadrant=(-1, -1))
Angle(l1, l2, other_angle=True)
Angle(l1, l2, quadrant=(1, -1), other_angle=True)
Angle(l1, l2, quadrant=(-1, 1), other_angle=True)
Angle(l1, l2, quadrant=(-1, -1), other_angle=True)
3.3 Points in the Angle
Angle
You can add a dot mark in the center, which helps us to distinguish between different angles when there are many angles in a picture.
pass (a bill or inspection etc)dot_radius
,dot_distance
cap (a poem)dot_color
and other parameters, you can adjust the size, position and color of the point.
line1 = Line(
LEFT / 2,
RIGHT / 2,
)
line2 = Line(
DOWN / 2,
UP / 2,
)
Angle(
line1,
line2,
dot=True,
dot_radius=0.02,
dot_color=RED,
)
Angle(
line1,
line2,
dot=True,
dot_radius=0.08,
dot_color=BLUE,
)
Angle(
line1,
line2,
dot=True,
dot_distance=0.2,
dot_color=GREEN,
)
Angle(
line1,
line2,
dot=True,
dot_distance=0.8,
dot_color=YELLOW,
)
3.4. Right-angle marking
Finally, there is a special angle marker - the right angle marker.
manim
There are 2 modules provided to mark right angles in theRightAngle
cap (a poem)Elbow
。
They display about the same, the difference being that theRightAngle
need to be generated based on two lines.
(indicates contrast)Elbow
A bit more flexible, it can generate right angle markers at any position.
line1 = Line(
LEFT / 2,
RIGHT / 2,
)
line2 = Line(
DOWN / 2,
UP / 2,
)
RightAngle(
line1,
line2,
length=0.2,
)
RightAngle(
line1,
line2,
length=0.4,
)
RightAngle(
line1,
line2,
quadrant=(1, -1),
)
RightAngle(
line1,
line2,
quadrant=(-1, -1),
)
Elbow(width=0.5)
Elbow(width=1)
Elbow(width=1, angle=PI / 2)
Elbow(width=1, angle=5 * PI / 4)
4. Annexes
The complete code for the article is on a web disk (),
Download at.Full Code (Access code: 6872)