Location>code7788 >text

manim learning-by-doing - Polar Plane

Popularity:922 ℃/2024-10-24 09:05:22

PolarPlane, as the name suggests, is the class used to create the polar plane.

Unlike the Cartesian coordinate system, the polar coordinate system locates points based on angles and radii, where each point is represented by aperspectivesand the distance from the origin ofgapindicated.

existManimMiddle.PolarPlaneThrough the pole diameter ($ r\() and polar angle (\) \theta $) to present the coordinate system, a representation that facilitates the handling of mathematical concepts related to angles and radii.

Whether it's a coordinate system grid, or a marker for coordinates, thePolarPlaneAll provide a visual presentation.

PolarPlaneIt is generally used to demonstrate polar functions, magnitude angles, and other math concepts related to polar coordinates.

1. Main parameters

polar coordinate systemThe parameters are the same as those previously described for theCartesian coordinate systemThe differences are significant and the main parameters are listed below:

Parameter name typology clarification
azimuth_step float Angular step between azimuthal (polar) markers
azimuth_units str Units of azimuth
azimuth_compact_fraction bool Whether to display azimuth labels in a compact fraction format
azimuth_offset float Offset of the azimuth, which affects the starting position of the angle
azimuth_direction str Direction of azimuthal increase
azimuth_label_buff float Distance of azimuth labels from polar plots
azimuth_label_font_size float Font size for azimuth labels
size float The size of the polar plane, if not specified, it will be calculated automatically according to radius_max.
radius_step float Spacing between radius markers
radius_max float Maximum value of the radius in the polar coordinate plane
radius_config dict Customize the style of the radius marker
background_line_style dict Background line style
faded_line_style dict Fade line style for controlling the style of auxiliary lines
faded_line_ratio int Control the proportion of faded lines

There are a couple of parameters above that need some additional clarification, the

one isazimuth_unitsparameter, which represents the unit of the azimuth, is fixed to the following five values:

  1. "PI radians":$ \pi \(arc, range\) [0, 2\pi] $
  2. "TAU radians":$ \tau \(arc, range\) [0, \tau] \(, where \) \tau = 2\pi $
  3. "degrees": Degrees, range $ [0, 360] $
  4. "gradians": Gradient, range $ [0, 400] $
  5. None: numeric value in the range $ [0, 1] $

there areazimuth_directionparameter, which has 2 values:

  1. CW: Clockwise
  2. CCW: Counterclockwise

2. Main approaches

PolarPlaneAlso inherits the coordinate systemCoordinateSystemmethod of the class

Among them, the following 2 methods are commonly used:

name (of a thing) clarification
add_coordinates Adding Axes and Scale Labels to the Polar Plane
plot_polar_graph Plot the image of the polar coordinate function $ r=f(\theta) $ in the polar coordinate plane

3. Examples of use

The following example shows how to use thePolarPlaneparameters and methods to create and customize polar planes.

3.1 Basic Polar Plane

This example creates a basic polar plane without much customization.

It's just enabled.add_coordinatesmethod to display the axis and scale labels.

plane = PolarPlane()
plane.add_coordinates()

3.2 Customizing angular units and ranges

This example first creates a polar plane and then customizes its angular units and range.

We set differentazimuth_unitscap (a poem)azimuth_stepvalue to change the units and spacing of the angle scale to make it denser or sparser for different display needs.

# Angle as a scale
plane1 = PolarPlane(
    azimuth_units="degrees",
    azimuth_step=12,
)
plane1.add_coordinates()

# Arc radius as a scale
plane2 = PolarPlane(
    azimuth_units="PI radians",
    azimuth_step=10,
)
plane2.add_coordinates()

# Gradient as gradient
plane3 = PolarPlane(
    azimuth_units="gradians",
    azimuth_step=20,
)
plane3.add_coordinates()

The above graphs are shown separately with different scales (perspectivesradiancap (a poem)gradient) and intervals (121020) demonstrates the polar coordinate system.

3.3. Customizing polar styles

This example demonstrates how to pass thePolarPlane(used form a nominal expression)background_line_styleparameters andfaded_line_styleparameter to control the polar coordinate system ofbackground linecap (a poem)fading lineThe display of the

The color and thickness of the line can be flexibly adjusted according to the display needs.

plane1 = PolarPlane(
    background_line_style={
        "stroke_color": RED,
        "stroke_width": 2,
        "stroke_opacity": 0.5,
    },
)

plane2 = PolarPlane(
    background_line_style={
        "stroke_color": YELLOW,
        "stroke_width": 4,
        "stroke_opacity": 0.5,
    },
    faded_line_style={
        "stroke_color": GREY,
        "stroke_width": 2,
        "stroke_opacity": 0.3,
    },
    faded_line_ratio=2,
)

plane3 = PolarPlane(
    background_line_style={
        "stroke_color": GREEN,
        "stroke_width": 2,
    },
    faded_line_style={
        "stroke_color": TEAL,
        "stroke_width": 1,
        "stroke_opacity": 0.6,
    },
    faded_line_ratio=2,
)

3.4. Polarized function images

In this example, we utilize thePolarPlane(used form a nominal expression)plot_polar_graphmethod to plot a function image in a polar coordinate system.

Plot a pattern of petals by the function: $ y=f(\theta)=3\times \sin(6\theta) $;

Plot a pattern of hearts through the function: $ y=f(\theta) =2.5\times (1-\sin(\theta)) $.

plane = PolarPlane(size=4)

# petals
r = lambda theta: 3 * (theta * 6)
graph1 = plane.plot_polar_graph(r, [0, 2 * PI], color=YELLOW)

# love
r = lambda theta: 2.5 * (1 - (theta))
graph2 = plane.plot_polar_graph(r, [0, 2 * PI], color=RED)

4. Annexes

The code in the article is just an extract of the key parts, the complete code is shared on a web disk (polar_plane.py),

Download at.Full Code (Access code: 6872)