Location>code7788 >text

manim learning by doing - angle marking

Popularity:201 ℃/2024-09-07 11:20:01

manimDrawing 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 angleangle markis an arc, and the degree of an arc is the same as the degree of an angle;

insofar asa right angleangle markIt's a vertical corner.

manimconsultations onangle markThere are 3 main models of the

  1. Angle: Draw angle markers based on two straight lines
  2. RightAngle: Under both articlesmutually perpendicularThe right angle markers are drawn on the lines of the
  3. Elbow: Right angle markings in any direction and size, not limited to straight lines

Among them.RightAngleModules 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

AngleModules 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 line2
False: 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.

RightAngleModules inherited fromAngleIn addition to the aboveAnglehas a parameter specific to itself in addition to the parameter of the

Parameter name typology clarification
length float Size of markers

Elbowmodule 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.

Elbowshape andRightAngleIt's the same.

2. Main approaches

AngleThere 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_pointsmethod, 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 areABCThree 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 ofBas the vertex and rotate counterclockwise from point A to point C.

methodologiesget_linesThe two lines that make up the angle can be obtained, i.e., in the figure aboveBABCTwo lines.

lines = angle.get_lines()

Finally.get_valuemethod 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 markersAngleis 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, thequadrantcap (a poem)other_angle

quadrantThere 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 theLine1upperstarting pointand inLine2upperfinishing position

For example, the following two lines that intersectquadrantThe first and second values of theLine1cap (a poem)Line2The position on it is shown in the figure.

other_angledefaultFalse, indicating that the angle is drawn fromLine1until (a time)Line2

set upother_angleis True, the angles are drawn in the opposite order, fromLine2until (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

AngleYou 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_radiusdot_distancecap (a poem)dot_colorand 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.

manimThere are 2 modules provided to mark right angles in theRightAnglecap (a poem)Elbow

They display about the same, the difference being that theRightAngleneed to be generated based on two lines.

(indicates contrast)ElbowA 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)