Location>code7788 >text

manim learn-by-doing - curved polygons

Popularity:756 ℃/2024-09-19 11:32:36

arc polygonIt's a combination ofcircular arccap (a poem)polygonalof shapes, this type of geometry is very widely used in design.

For example, in home design, look at the home of the sofa, dining table and seats, their corners, backrests and other places are curved design, this design effectively softens the interior space, so that the overall atmosphere is more harmonious and natural.

There are also landscape and architectural designs where curved polygons are often used for road planning, flower bed layouts, and so on.

Especially the children's play area, through the free arc design, not only in line with the children's lively and active nature, but also to stimulate their imagination and creativity.

In the field of art and design, curved polygons are used more often, in the creation of graphics, logos, posters, etc., the unique shape and visual effect of curved polygons can attract the attention of the audience, and convey the designer's intentions and emotions.

manimThere are 2 modules provided to construct curved polygons:

  1. ArcPolygon: ByVertex and radianto construct curved polygons
  2. ArcPolygonFromArcs: Bycircular arcto construct curved polygons

The main difference between these two modules is the construction of the curved polygonalThe process is different, one through the vertices and one through the arcs.

The final constructed curved polygon is no different.

1. Main parameters

ArcPolygonThe main parameters are:

Parameter name typology clarification
vertices Point3D List of vertices of a polygon
angle float Set the radian of all arcs uniformly
radius float Set the radius of all arcs uniformly
arc_config list[dict] Set the radian of each arc separately

verticeverticesAfter determining thatanglecap (a poem)radiusSets the degree of curvature of the arc between every two vertices.

anglecap (a poem)radiusOnly one parameter can be used, and if both are used, theangleThe parameter is invalid.

anglecap (a poem)radiusis to set the radians of all arcs of a polygon uniformly.arc_configYou can set each arc to have a different radian.

ArcPolygonFromArcsThe parameters are relatively simple.

Parameter name typology clarification
arcs Arc set of arcs

Note that if the parameter is passed in as an arc listarcscannot form a closed polygon.

So.manimwill automatically associatearcsThe end point of the last arc in the center is connected to the start point of the first arc with a straight line to form a closed polygon.

These two modules (ArcPolygoncap (a poem)ArcPolygonFromArcs) There is no difference between the constructed arc polygons, and different modules are selected according to the actual situation when creating the animation.

If vertex information is available, then useArcPolygonto construct the polygon, and if there is information about the individual arcs, then use theArcPolygonFromArcsto construct polygons.

2. Examples of use

2.1 Harmonization of the setting of arcs

utilizationangleYou can set the radian of each edge in an arc polygon uniformly; the larger the radian is set, the more curved the edge will be.

vertices = [UR, UL, DL, DR]

ArcPolygon(*vertices, angle=0)
ArcPolygon(*vertices, angle=60 * DEGREES)
ArcPolygon(*vertices, angle=120 * DEGREES)

2.2 Harmonization of radii

utilizationradiusIt is also possible to set the curvature of each edge in an arc polygon.radiusis the radius of the circle in which the two vertices forming the arc are located.

the reason whyradiusThe larger it is, the less curvature of the edge.

vertices = [UR, UL, DL, DR]

ArcPolygon(*vertices, radius=10)
ArcPolygon(*vertices, radius=1)
ArcPolygon(*vertices, radius=2)

2.3. set up each arc separately

parametersanglecap (a poem)radiusis used to set the curvature of all edges uniformly.

If we want to set a different radian for each side of an arc polygon, we have to use thearc_configParameters.

vertices = [UR, UL, DL, DR]

arc_config = [
    {"angle": 30 * DEGREES},
    {"angle": 90 * DEGREES},
    {"radius": 2},
    {"radius": 5},
]

ArcPolygon(*vertices, arc_config)

pass (a bill or inspection etc)arc_configNot only can you set the curvature of each arc, but you can also set their line thickness, color, and other properties.

2.4 Constructing polygons from arcs

ArcPolygonFromArcsis constructing the polygon from a series of arcs, so there is no need for theanglecap (a poem)radiusThese parameters are up.

This is because the curvature and related properties of the arcs are already set when each arc is constructed.

arc1 = ArcBetweenPoints(
    angle=PI / 6, # 30degree (angles, temperature etc)
    color=BLUE,
)
arc2 = ArcBetweenPoints(
    angle=PI / 3, # 60degree (angles, temperature etc)
    color=GREEN,
)
arc3 = ArcBetweenPoints(
    angle=PI / 2, # 90degree (angles, temperature etc)
    color=YELLOW,
)
arc4 = ArcBetweenPoints(
    angle=2 * PI / 3, # 120degree (angles, temperature etc)
    color=RED,
)

ArcPolygonFromArcs(arc1, arc2, arc3, arc4)

2.5 Polygons with missing arcs

The above example uses theArcPolygonFromArcsWhen constructing a polytope, the incoming 4 arcs together are exactly closed.

What happens if the incoming arc is not closed?

ArcPolygonFromArcswill automatically connect the non-closed parts with straight lines.

That is, the end point of the previous arc is connected to the start point of the next arc by a straight line, eventually forming a closed polygon.

arc1 = ArcBetweenPoints(
    angle=PI / 6, # 30degree (angles, temperature etc)
    color=BLUE,
)
arc3 = ArcBetweenPoints(
    angle=PI / 2, # 90degree (angles, temperature etc)
    color=YELLOW,
)

ArcPolygonFromArcs(arc1, arc3)

The missing part is the part connected by the white straight line above.

3. Annexes

The complete code for the article is on a web disk (arc_polygon.py),

Download at.Full Code (Access code: 6872)