Location>code7788 >text

manim learn-by-doing - round shape

Popularity:933 ℃/2024-08-20 10:12:13

A circular shape can be considered a special kind of circle that is part of a circle.
manimin which several modules are packaged separately for circular shapes:

  1. Arc: Generalized arcs, drawing arcs based on radius and angle
  2. ArcBetweenPoints: Drawing arcs based on two points and angles
  3. AnnularSector: a circular arc that is equivalent to being part of a circle
  4. Sector: scalloped, always 1/4 circle.

Among them.ArcBetweenPointscap (a poem)AnnularSectorinherited fromArcSectorinherited fromAnnularSector


Circular Arc SeriesThe module is located in themanimhit the nail on the headMobjectUnder.

1. Main parameters

module (in software)ArcThe main parameters are:

Parameter name typology clarification
radius float radius of a circular arc
start_angle float The arc of the beginning of the circle
angle float Curvature of the arc
num_components int The segments that make up an arc. The larger the value, the more rounded the arc is.
arc_center Point3D The position of the center of the circle corresponding to the arc

The start and end points of a circular arc are determined by thestart_anglecap (a poem)angleControlled.
start_angleparameter controls the starting point of the arc, the default value is0(The right side of the center of the circle is0 degrees);
angleparameter is the radian of the arc.start_angle + angleThe value of is the endpoint of the arc, the
angleis calculated counterclockwise.

module (in software)ArcBetweenPointsThe main parameters are:

Parameter name typology clarification
start Point3D Starting point of the arc
end Point3D end of a circular arc
angle float Curvature of the arc
raduis float radius of a circular arc

This module is based on two points (startcap (a poem)end) to draw arcs.
anglecap (a poem)raduisOnly one parameter can be set to control the arc length of the arc.
startcap (a poem)endFixed whenangleThe larger it is, the longer the arc length;raduisThe larger it is, the shorter the arc length.

module (in software)AnnularSectorThe main parameters are:

Parameter name typology clarification
inner_radius float Inner radius of a circular arc
outer_radius float Outer radius of circular arc
start_angle float The arc at the beginning of a circular arc
angle float The curvature of the circular arc

inner_radiuscap (a poem)outer_radiusThe difference formed a loop;
start_anglecap (a poem)angleMeaning and ModuleArcThe same as the parameter of the same name in the

module (in software)SectorThe main parameters of the

Parameter name typology clarification
inner_radius float Inner radius of a circular arc
outer_radius float Outer radius of circular arc

SectorModule onlyinner_radiuscap (a poem)outer_radiustwo parameters, since it defaults to 1/4 of a circle.

2. Main approaches

The role of these modules is mainly to display graphics, so there are not many methods, and two are commonly used:

name (of a thing) clarification
get_arc_center Get the coordinates of the current center of the arc.
move_arc_center_to Setting the coordinates of the new center of the arc

3. Examples of use

The following demonstrates some examples for the parameters of each of the 4 circular shaped modules.

3.1 Generalized arcs

Generalized arcsArcis the most commonly used.start_anglecap (a poem)angleSets the starting point and radian of the arc.
arc_centerSets the position of the arc.radiusControls the size of the arc.

Arc(
    arc_center=LEFT * 2,
    angle=PI,
)
Arc(
    radius=1.5,
    arc_center=RIGHT,
    angle=PI,
)
Arc(
    start_angle=PI / 2,
    angle=PI / 2,
    arc_center=LEFT * 2 + DOWN * 2,
)
Arc(
    start_angle=PI,
    angle=PI * 3 / 2,
    arc_center=RIGHT + DOWN * 1.5,
)

3.2 Generating arcs from two points

Generate arcs from fixed two pointsArcBetweenPointsis also commonly used when creating animations.
parametersstartcap (a poem)endSets the start and end points of the arc;
anglecap (a poem)radiusSets the degree of curvature of the arc, only one of these two parameters can be used, and when set at the same time only theradiusbe born

ArcBetweenPoints(
    start.get_center(),
    end.get_center(),
    radius=0.8,
)

ArcBetweenPoints(
    start.get_center(),
    end.get_center(),
    radius=1.6,
)

ArcBetweenPoints(
    start.get_center(),
    end.get_center(),
    angle=PI / 2,
)

ArcBetweenPoints(
    start.get_center(),
    end.get_center(),
    angle=PI,
)

The first two examples useradiusto control the degree of the arc, the last two examples use theangleControls the degree of the arc.

3.3. Arc of the ring

Circular ArcAnnularSectorIt can be interpreted as an arc with increased thickness.
It can be usedArcparameter, which differs in that it has two radii, ainner_radiusOne isouter_radius
The difference between these two radii is the thickness of the ring.

AnnularSector(
    inner_radius=0.5,
    outer_radius=1.5,
    angle=PI,
)
AnnularSector(
    inner_radius=0.5,
    outer_radius=0.8,
    angle=PI,
)
AnnularSector(
    start_angle=PI / 2,
    angle=PI / 2,
    inner_radius=0.5,
    outer_radius=1.5,
)
AnnularSector(
    start_angle=PI,
    angle=PI * 3 / 2,
    inner_radius=0.5,
    outer_radius=0.8,
)

3.4. Sector

sectorSectorIt is a simplifiedAnnularSectorIt is fixed to1/4A circle.

Sector(
    inner_radius=0.5,
    outer_radius=1.5,
)
Sector(
    inner_radius=0.5,
    outer_radius=0.8,
)
Sector(
    inner_radius=1,
    outer_radius=1.5,
)
Sector(
    inner_radius=0.3,
    outer_radius=1.8,
)

4. Annexes

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