polygonalIt is a common geometric structure that has a seemingly infinite variety of shapes, all of which can actually be made from a combination of several commonly used polygons.
This article introducesmanim
There are several drawing options available in theCommon Polygonsof the module.
-
Triangle
: equilateral triangle -
Square
: Square -
Rectangle
: Rectangular -
RoundedRectangle
: rectangle with rounded corners -
Star
: a regular polygon with no intersecting lines, resembling a star with pointed corners.
1. Main parameters
Of these modules.Triangle
At its simplest, it has no parameters specific to itself.
Square
There is one parameter:
Parameter name | typology | clarification |
---|---|---|
side_length | float | Length of the sides of the square |
Rectangle
Slightly more complex, it can be evenly chunked to form tables.
Parameter name | typology | clarification |
---|---|---|
height | float | Height of rectangle |
width | float | Width of rectangle |
grid_xstep | float | The width of each column after dividing the rectangle |
grid_ystep | float | The height of each row after dividing the rectangle |
RoundedRectangle
inherited fromRectangle
You can use theRectangle
of all the parameters of the
In addition, it has a parameter specific to itself.
Parameter name | typology | clarification |
---|---|---|
corner_radius | float | list[float] |
RoundedRectangle
The curvature of the four corners can be set uniformly or to different curvatures.
Star
The module is so named because it draws shapes that look like little stars.
Parameter name | typology | clarification |
---|---|---|
n | int | How many pointed corners does a star shape have |
outer_radius | float | Radius of the outer circle of the graph |
inner_radius | float | Radius of the tangent circle of the graph |
density | int | The density of the sharp corners of the graph, valid when inner_radius is set. |
start_angle | float | The angle at which the vertex starts |
If you do not understand the meaning of these properties, it does not matter, later combined with examples to show the difference between the star-shaped graphic under different parameters.
It will be able to see a little more clearly.
2. Examples of use
2.1 Equilateral triangles and squares
equilateral triangleTriangle
Sort of the simplest polygon, it has no parameters, the
But it can be done byscale
,rotate
etc. to change its size and angle.
Triangle()
# Zoom in 1.5 times
Triangle().scale(1.5)
# Rotate 180 degrees
Triangle().rotate(PI)
squareSquare
It's also simple, it has only one parameter, setting the length of the sides of the square.
Square(side_length=0.5)
Square(side_length=1)
Square(side_length=2)
The above code is displayed as follows:
2.2. rectangular
rectangularRectangle
In addition to being able to set the widthwidth
heightsheight
, which can also be chunked.
The so-called chunking is done bygrid_xstep
respond in singinggrid_ystep
The parameter tells the rectangle to be split into smaller rectangles.
The width of each small rectangle iswidth / grid_xstep
The height isheight / grid_ystep
。
Rectangle(width=2, height=1)
Rectangle(width=1, height=3)
# split2classifier for objects in rows such as words3Rectangle of columns
Rectangle(
width=3,
height=2,
grid_xstep=1,
grid_ystep=1,
)
2.3 Rounded rectangles
rectangle with rounded cornersRoundedRectangle
respond in singingrectangularRectangle
The difference is that it can set the curvature of the 4 corners.
Rectangle
has the parameter thatRoundedRectangle
can also be used, including the parameters for chunking.
# 4 corners have the same curvature
RoundedRectangle(
corner_radius=0.4,
)
# Same curvature on the diagonal
RoundedRectangle(
corner_radius=[0.2, 0.6], ) # Same diagonal curvature RoundedRectangle(
)
# All 4 corners have different curvatures
RoundedRectangle(
corner_radius=[0.1, 0.6, 0.3, 0.9], ) # The 4 corners have different curvatures.
)
2.4. stars
star polygonStar
It is a special type of concave polygon that is often used as a decorative pattern and design element because of its unique shape and symmetry.
Star
The module can be parameterized by the number of sharp corners and the density of the sharp corners.
Star(n=5)
# The higher the density, the denser the corners look
Star(n=9, density=2)
Star(n=9, density=4)
3. Annexes
The complete code for the article is on a web disk (),
Download at.Full Code (Access code: 6872)