a plane with right anglesNumberPlane
beManim
Objects in the library for creating 2D coordinate planes, which help the user to visualize axes and gridlines in the scene.
With axes, gridlines, and scales, it dynamically displays function curves, geometric shapes, and their transformations, making complex mathematical concepts intuitive and easy to understand.
NumberPlane
offersx-axiscap (a poem)y-axiswhich is usually centrosymmetric.
By default, theNumberPlane
A background grid will be displayed, which is very helpful for displaying math functions, geometric shapes, and so on.
We can define the extent of the coordinate plane, add labels to the axes, and place other shapes, functions, or animations on theNumberPlane
on, thus demonstrating math concepts in an animation.
As described belowManim
hit the nail on the headNumberPlane
objects as well as some common usage examples.
1. Main parameters
NumberPlane
The main parameters are:
Parameter name | typology | clarification |
---|---|---|
x_range | Sequence[float] | the plane of right angleshorizontal coordinate axisRange, Interval |
y_range | Sequence[float] | the plane of right anglesvertical coordinate axisRange, Interval |
x_length | float | Right Angle Plane Width |
y_length | float | Right Angle Plane Height |
background_line_style | dict | Right Angle Plane Background Gridline Style |
faded_line_style | dict | Fade gridline style for secondary background gridlines |
faded_line_ratio | int | Define the ratio of the fade gridlines to the background gridlines |
make_smooth_after_applying_functions | bool | Whether smoothing is performed after applying the function |
In the right-angled plane, it is common to have coordinate axes and background grid lines whose styles are passed through thebackground_line_style
parameter to set.
In addition.NumberPlane
There's another one in there.faded_line_style
parameter, which defines the style of the faded grid lines.
These faded gridlines are often used to supplement the background gridlines to provide a more detailed visual effect or to help distinguish between different coordinate areas.
In general, there is no need to usefaded_line_style
cap (a poem)faded_line_ratio
。
2. Main approaches
Manim
The coordinate system in theCoordinateSystem
Classes provide a number of methods, including:
- Methods for getting and setting coordinate system properties
- Method of converting coordinates in a coordinate system to on-screen coordinates
- Methods of drawing shapes (points, lines, surfaces, etc.) in the coordinate system
The following introduction to the various coordinate systems will be used in the example used in the method, here will not be introduced one by one.
(indicates contrast)NumberPlane
inherited fromCoordinateSystem
class, so you can use its various methods directly.
3. Examples of use
Here are a few examples to showNumberPlane
The function of the
3.1 Basic two-dimensional coordinate plane
By default, theNumberPlane
Displays axes and background gridlines to help users clearly see the division of the coordinate system.
The coordinate axes are white by default and the background gridlines are blue by default.
The following example shows a standard two-dimensional coordinate plane, containing thex-axiscap (a poem)y-axis,
x-axiscap (a poem)y-axisThe range of each is set to-7~7
cap (a poem)-4~4
The grid lines are spaced1
。
plane = NumberPlane(
x_range=[-7, 7],
y_range=[-4, 4],
x_length=6,
y_length=4,
)
3.2. Customizing grid line styles
NumberPlane
The styles of the background gridlines and the fade gridlines of the
The following example provides an overview of theBackground gridlinescap (a poem)Fade gridlinesThe color, width and transparency are set.
The background gridlines are cyan and the fade gridlines are gray.
plane = NumberPlane(
x_range=[-7, 7],
y_range=[-4, 4],
x_length=6,
y_length=4,
background_line_style={
"stroke_color": TEAL,
"stroke_width": 4,
"stroke_opacity": 0.6,
},
faded_line_style={
"stroke_color": GREY,
"stroke_opacity": 0.3,
},
faded_line_ratio=2,
)
Note that this also sets thefaded_line_ratio=2
It means that every 1 frameBackground gridlinesEquivalent to 2 compartments ofFade gridlines。
3.3 Axes of different scales
By default, theNumberPlane
(used form a nominal expression)X-axiscap (a poem)Y-axisThe intervals of the
In fact, by setting different coordinate ranges and display ranges, you can create axes with different scales.
That is, the Y-axis interval can be greater than the X-axis interval or less than the X-axis interval.
# Y-axis spacing is greater than X-axis spacing
plane1 = NumberPlane(
y_length=3, )
)
# y_range is less than x_range
plane2 = NumberPlane(
x_range=[-3, 3], y_range=[-7, 7], x_length=3, )
x_length=3,
y_length=3, )
)
3.4. Plotting function images
utilizationNumberPlane
The greatest use lies in the ability to plot the image of a function in it, an image or a geometric figure in a coordinate system, the
It can be easier to locate their positions and adjust the transformation relationship between them.
The following example plots 2 functions in a coordinate system, using the plotting methods provided by the coordinate system base class:plot_parametric_curve
。
plane = NumberPlane(
x_range=[-4, 4],
y_range=[-16, 16],
x_length=6,
y_length=4,
)
g1 = plane.plot_parametric_curve(
lambda x: [x, x**2],
t_range=[-3.5, 3.5, 0.01],
)
g2 = plane.plot_parametric_curve(
lambda x: [x, x**3],
t_range=[-2.5, 2.5, 0.01],
)
4. Annexes
The code in the article is just an extract of the key parts, the complete code is shared on a web disk (number_plane.py
),
Download at.Full Code (Access code: 6872)