Cone
beManim
is specialized in the creation and manipulation ofTapered Geometric ObjectsThe class.
Cone
Allows the user to define the base radius, height, color, opacity and other attributes of the cone, and provides a series of methods to manipulate this cone, such as moving, scaling, rotating and so on.
With these properties and methods, users have the flexibility to create tapered objects that meet their needs and incorporate them into animations or presentations.
1. Main parameters
Cone
The main parameters are:
Parameter name | typology | clarification |
---|---|---|
base_radius | float | Radius of the bottom of the cone |
height | float | The height of the cone, which is the perpendicular distance of the cone from the center of the base to the vertex |
direction | Orientation of the cone | |
show_base | bool | Whether to display the base of the cone |
v_range | list[float] | Range of cone longitudinal scans for controlling the longitudinal shape of cone flanks |
u_min | float | Minimum angle for transverse scanning of cones, affecting the lateral distribution of cone flanks |
checkerboard_colors | bool | Whether or not to use a checkerboard color pattern to help visually distinguish different parts of the cone |
These parameters allow the user the flexibility to create and customize cone objects.
For example.
- By adjusting
base_radius
cap (a poem)height
parameter, you can change the size and shape of the cone; - pass (a bill or inspection etc)
direction
parameter, you can control the orientation of the cone; - (indicates contrast)
show_base
、v_range
、u_min
cap (a poem)checkerboard_colors
parameter provides further customization of the visual representation of the cone.
2. Main approaches
Cone
class has two methods specific to itself for changing direction:
name (of a thing) | clarification |
---|---|
get_direction | Used to obtain the direction vector of a cone. This direction vector is usually a three-dimensional vector that represents the orientation of the cone in space. |
set_direction | Used to set the orientation vector of the cone. The orientation of the cone in space can be changed by passing in a new 3D vector. |
3. Examples of use
The following example shows how to create a cone object, set its parameters, and call its methods to change or animate the properties of the cone.
3.1. Basic cones
This example shows how theManim
Create a basic cone in the scene.
The cone has a specified base radius and height and is oriented upward by default.
# Create a cone with a base radius of 1 and a height of 2.
# Orientation up (default orientation)
cone = Cone(base_radius=1, height=2)
3.2. Customized cones
In this example, a cone is created and customized.
This consists of setting the cone offill color、Border Color、Border width, as well as moving it to the scene'sspecific location。
In this way, the cone not only has a unique appearance, but is also located in a user-specified position.
# create a cone with a base radius of 1.5 and a height of 3.
# Set the fill color and border color
cone = Cone(
base_radius=1.5,
height=3, # fill_color=RED, # set the fill color and border color.
fill_color=RED, stroke_color=YELLOW
stroke_width=2, )
)
# Move the cone to a specific location in the scene
cone.move_to(([1, 1, 1]))
3.3 Rotation and scaling
This example shows how to animate a cone.
First, a cone was created and two types of animation were subsequently applied: rotation and scaling.
The cone is first rotated around the y-axis by a certain angle and then scaled up.
# Create a cone with a base radius of 1 and a height of 2
cone = Cone(
base_radius=1,
height=2,
fill_color=BLUE, )
)
# Add the cone to the scene
(Create(cone))
# Create a rotation animation, rotating 90 degrees around the y-axis
(
Rotate(
cone, axis=Y_AXIS, # Rotate the cone 90 degrees around the y-axis.
axis=Y_AXIS, angle=PI / 2,
angle=PI / 2, ), rotate(
), ), (rotate, axis=Y_AXIS, angle=PI / 2, ), (
)
# Create a zoom animation that scales the cone by a factor of 1.5
((1.5))
3.4 Duplication and alignment
This example shows how to copy cones and arrange them in a row.
First, a cone was created as a template, and then multiple copies of that cone were created using a loop that shifted their positions slightly to line them up.
# Create a cone with a base radius of 0.5 and a height of 1 as a template
cone_tpl = Cone(
base_radius=0.5,
height=1,
fill_color=GREEN,
)
# Create an array of cones.
# Each cone is a copy of the template, with a slight shift in position
cones = VGroup(
*[cone_tpl.copy().move_to([i, 0, 0]) for i in range(5)]
)
# Add the array of cones to the scene
(Create(cones))
# Move the entire array of cones together
((LEFT * 3))
4. Annexes
The code in the article is just an extract of the key parts, the complete code is shared on a web disk (),
Download at.Full Code (Access code: 6872)