existmanim
The Circle class is a fundamental and powerful module in the rich library of graphics.
Whether it's a simple circle drawing or a complex circle transformation, it can be realized with concise code.
manim
There are 3 main modules associated with the Middle Circle class:
-
Circle
: Standard round -
Annulus
: Circular shape -
Ellipse
ellipsoid
Among them.Annulus
cap (a poem)Ellipse
inherited fromCircle
。
Round Seriesbe in (some state, position, or condition)manim
hit the nail on the headMobject
Under.
1. Main parameters
unit of Chinese currency (Yuan)Circle
The object has few properties, mainly:
Parameter name | typology | clarification |
---|---|---|
radius | float | radius |
color | str | color |
stroke_width | float | Bezel Thickness |
fill_opacity | float | transparency |
traffic circleAnnulus
The main properties of the object are:
Parameter name | typology | clarification |
---|---|---|
inner_radius | float | Inner circle radius |
outer_radius | float | outer ring radius |
color | str | color |
mark_paths_closed | bool | TODO |
Annulus
renderableinner_radius
cap (a poem)outer_radius
The part between, that is, a ring.
ellipsesEllipse
The main properties of the object are:
Parameter name | typology | clarification |
---|---|---|
width | float | ellipse width |
height | float | ellipse height |
ellipsesWhen the width and height are set to the same, it is the standardunit of Chinese currency (Yuan)。
2. Main approaches
unit of Chinese currency (Yuan)Circle
Objects have 3 common methods:
name (of a thing) | clarification |
---|---|
from_three_points | Draw a circle based on 3 points |
point_at_angle | Returns the position of a point on a circle |
surround | Modifies a circle so that it surrounds the given object |
See the following for the usage of the above methodusage exampleChapters.
traffic circleAnnulus
(math.) and ellipseEllipse
There is no common method.
3. Examples of use
3.1. size and color
For roundCircle
For example, through the radiusradius
to adjust the size;
For ringsAnnulus
For example, through the inner radiusinner_radius
and outer radiusouter_radius
to adjust the size and thickness of the ring;
For ellipsesEllipse
For example, bywidth
cap (a poem)height
to adjust the size and flatness of the ellipse.
All three shapes are coloredcolor
Properties.
# orbicular
Circle(radius=0.1, color=RED)
Circle(radius=0.3, color=BLUE)
Circle(radius=0.5, color=YELLOW)
# traffic circle
Annulus(
inner_radius=0.1,
outer_radius=0.2,
color=RED,
)
Annulus(
inner_radius=0.4,
outer_radius=0.5,
color=BLUE,
)
Annulus(
inner_radius=0.4,
outer_radius=0.8,
color=YELLOW,
)
# ellipses
Ellipse(
width=0.3,
height=0.1,
color=RED,
)
Ellipse(
width=0.8,
height=0.4,
color=BLUE,
)
Ellipse(
width=1.8,
height=1,
color=YELLOW,
)
The effect is as follows:
3.2 Drawing a circle from three points
In addition to setting the radius by the aboveradius
The way to draw a circle can also be based on an arbitrarythree-pointto generate a circle.
utilizationfrom_three_points
Methods.
d1 = Dot(RIGHT, color=RED)
d2 = Dot(UL, color=BLUE)
d3 = Dot(DR, color=GREEN)
Circle.from_three_points(
d1.get_center(),
d2.get_center(),
d3.get_center(),
color=YELLOW,
)
3.3. Getting a point on a circle
By means of methodspoint_at_angle
, we can get a point on the circle based on the angle.manim
Taking the rightmost point of the whole circle (at the same height as the center of the circle) as an angle of\(0^\circ\)The point of the
Then gradually increase the angle counterclockwise.
c = Circle(radius=2, color=YELLOW)
# Point at 60 degrees
p1 = c.point_at_angle(PI / 6)
# Point at 180 degrees
p2 = c.point_at_angle(PI)
# Point at 270 degrees
p3 = c.point_at_angle(3 * PI / 2)
3.4 Surrounding other shapes with circles
And finally, there's asurround
method, which has the primary effect of wrapping a circle around another figure.surround
The method has abuffer_factor
parameters.
(coll.) fail (a student)buffer_factor >= 1
when the circle wraps around the outside of the graph; when thebuffer_factor < 1
When the circle is inside the graph.
# Star graphics
star = Star()
# buffer_factor=1
# So surround the outside of the star
Circle().surround(star, buffer_factor=1)
# Crosshair graphics
vg = VGroup(
Line(UP / 2, DOWN / 2), Line(LEFT / 2, RIGHT / 2), VG = VGroup()
Line(LEFT / 2, RIGHT / 2), )
)
# Default buffer_factor=1.2
# So the surround is outside the crosshairs
Circle().surround(vg)
# Triangle graphics
t = Triangle()
# buffer_factor<1
# So the circle is inside the triangle
Circle().surround(t, buffer_factor=0.3)
4. Annexes
The complete code for the article is on a web disk (),
Download at.Full Code (Access code: 6872)