A package for tools and extensions in Manim
Project description
manim_extensions
中文
manim_extensions 是一个用于 Manim 的扩展工具包,提供了中文公式渲染、几何计算、带标注的图形以及常用动画效果,帮助你更高效地制作数学动画。
安装
pip install manim_extensions
依赖:manim
模块概览
| 模块 | 说明 |
|---|---|
mobjects |
Mobject 类扩展,包含中文公式、带标签圆点、可延长线段等 |
geometry |
纯几何计算函数,用于求交点、切点等 |
animations |
动画效果,如可视化绘弧、打字机效果 |
mobjects 模块
ChineseMathTex(*texts, font="SimSun", tex_to_color_map={}, **kwargs)
支持中文显示的 MathTex 子类。可直接在公式中写入中文,无需手动包裹 \text{}。
from manim_extensions import ChineseMathTex
formula = ChineseMathTex(
"\\frac{1}{2} + 你好 = x",
tex_to_color_map={"你好": RED},
font="SimSun"
)
参数
*texts— LaTeX 文本字符串font— 中文字体名称,默认"SimSun"tex_to_color_map— 文本到颜色的映射字典,默认{}**kwargs— 传递给MathTex的其他参数
LabelDot(dot_label, dot_pos, label_pos=DOWN, buff=0.1, **kwargs)
在指定位置创建一个圆点,并在其旁边添加 MathTex 标签。
from manim_extensions import LabelDot
dot = LabelDot("A", [1, 2, 0], label_pos=UP, buff=0.2)
参数
dot_label— 标签文本dot_pos— 圆点位置label_pos— 标签相对圆点的方向,默认DOWNbuff— 标签与圆点的间距,默认0.1**kwargs— 传递给VGroup的其他参数
MathTexLine(formula, direction=UP, buff=0.5, **kwargs)
创建一条线段,并在其指定方向旁放置 MathTex 公式。
from manim_extensions import MathTexLine
line = MathTexLine(MathTex("y = x"), direction=UP, color=BLUE)
参数
formula—MathTex公式对象direction— 公式相对线段的方向,默认UPbuff— 公式与线段的间距,默认0.5**kwargs— 传递给Line的其他参数
MathTexBrace(target, formula, direction=UP, buff=0.5, **kwargs)
为指定对象创建一个花括号,并在其旁边放置 MathTex 公式。
from manim_extensions import MathTexBrace
line = Line(LEFT, RIGHT)
brace = MathTexBrace(line, MathTex("\\Delta x"), direction=UP)
参数
target— 要被花括号标注的目标对象formula—MathTex公式对象direction— 公式与花括号相对目标的方向,默认UPbuff— 公式与花括号的间距,默认0.5**kwargs— 传递给Brace的其他参数
MathTexDoublearrow(formula, direction=UP, buff=0.5, **kwargs)
创建一个双向箭头,并在其指定方向旁放置 MathTex 公式。
from manim_extensions import MathTexDoublearrow
arrow = MathTexDoublearrow(MathTex("\\Leftrightarrow"), direction=DOWN)
参数
formula—MathTex公式对象direction— 公式相对箭头的方向,默认UPbuff— 公式与箭头的间距,默认0.5**kwargs— 传递给DoubleArrow的其他参数
ExtendedLine(line, extend_distance, **kwargs)
基于一条已有的 Line,在其两端按原方向各延长指定距离。
from manim_extensions import ExtendedLine
original = Line(LEFT, RIGHT)
extended = ExtendedLine(original, extend_distance=1.0, color=RED)
参数
line— 原始线段extend_distance— 两端各延长的距离**kwargs— 传递给Line的其他参数
geometry 模块
CircleInt(circle1, circle2)
计算两个圆的交点。
from manim_extensions import CircleInt
c1 = Circle(radius=2).shift(LEFT)
c2 = Circle(radius=2).shift(RIGHT)
result = CircleInt(c1, c2) # ([x1, y1, 0], [x2, y2, 0]) 或 None
返回
- 若相交,返回两个交点坐标的元组
([x, y, 0], [x, y, 0]) - 若不相交,返回
None
LineCircleInt(line, circle)
计算线段与圆的交点,仅返回落在线段参数范围 [0, 1] 内的交点。
from manim_extensions import LineCircleInt
line = Line(LEFT * 3, RIGHT * 3)
circle = Circle(radius=1)
result = LineCircleInt(line, circle)
返回
- 两个交点、一个交点,或
None
LineInt(line1, line2)
在二维平面上计算两条无限延长线段的交点(不限制在线段端点范围内)。
from manim_extensions import LineInt
l1 = Line(LEFT, RIGHT)
l2 = Line(DOWN, UP)
result = LineInt(l1, l2) # [0.0, 0.0, 0] 或 None
返回
- 交点坐标
[x, y, 0],或平行时返回None
LineArcInt(line, arc)
计算线段与圆弧的交点,会检查交点是否真正落在圆弧的角度范围内。
from manim_extensions import LineArcInt
line = Line(LEFT, RIGHT)
arc = Arc(start_angle=0, angle=PI, radius=1)
result = LineArcInt(line, arc)
返回
- 两个交点、一个交点,或
None
TangentPoint(p1, p2, line_start, line_end)
计算以 p1 和 p2 为圆上点、且与线段相切的切点坐标。
from manim_extensions import TangentPoint
p = TangentPoint(
[1, 0, 0], [-1, 0, 0],
line_start=[0, -2, 0], line_end=[0, 2, 0]
)
参数
p1,p2— 圆上的两个点,格式(x, y)或(x, y, z)line_start,line_end— 线段的起点和终点
返回
- 切点坐标
np.ndarray,若无法计算则返回None
animations 模块
VisDrawArc(scene, arc, axis=OUT, run_time=1)
可视化绘制圆弧的动画,会同时显示一个沿圆弧移动的点及半径虚线。直接调用即可,无需放入 self.play() 中。
from manim_extensions import VisDrawArc
class MyScene(Scene):
def construct(self):
arc = Arc(start_angle=0, angle=PI, radius=2)
VisDrawArc(self, arc, axis=OUT, run_time=2)
参数
scene— Manim 场景对象arc— 要绘制的Arcaxis— 旋转方向,OUT为逆时针,IN为顺时针,默认OUTrun_time— 动画时长(秒),默认1
TypeWriter(mobject, interval=2, **kwargs)
打字机效果动画,逐个字符显示 Text 对象的内容。自动根据字符数量与间隔计算动画总时长。
from manim_extensions import TypeWriter
class MyScene(Scene):
def construct(self):
text = Text("Hello World")
self.play(TypeWriter(text, interval=0.1))
参数
mobject—Text对象interval— 字符间显示间隔(秒),默认2**kwargs— 传递给Animation的其他参数
English
manim_extensions is an extension toolkit for Manim, providing Chinese formula rendering, geometric calculations, annotated graphics, and common animation effects to help you create mathematical animations more efficiently.
Installation
pip install manim_extensions
Dependency: manim
Module Overview
| Module | Description |
|---|---|
mobjects |
Mobject class extensions, including Chinese formulas, labeled dots, extendable lines, etc. |
geometry |
Pure geometric calculation functions for finding intersections, tangent points, etc. |
animations |
Animation effects, such as visualized arc drawing and typewriter effects |
mobjects Module
ChineseMathTex(*texts, font="SimSun", tex_to_color_map={}, **kwargs)
A MathTex subclass that supports Chinese characters. You can write Chinese directly in the formula without manually wrapping it in \text{}.
from manim_extensions import ChineseMathTex
formula = ChineseMathTex(
"\\frac{1}{2} + 你好 = x",
tex_to_color_map={"你好": RED},
font="SimSun"
)
Parameters
*texts— LaTeX text stringsfont— Chinese font name, default"SimSun"tex_to_color_map— Dictionary mapping text to colors, default{}**kwargs— Other arguments passed toMathTex
LabelDot(dot_label, dot_pos, label_pos=DOWN, buff=0.1, **kwargs)
Creates a dot at the specified position and adds a MathTex label next to it.
from manim_extensions import LabelDot
dot = LabelDot("A", [1, 2, 0], label_pos=UP, buff=0.2)
Parameters
dot_label— Label textdot_pos— Dot positionlabel_pos— Direction of the label relative to the dot, defaultDOWNbuff— Spacing between label and dot, default0.1**kwargs— Other arguments passed toVGroup
MathTexLine(formula, direction=UP, buff=0.5, **kwargs)
Creates a line segment and places a MathTex formula next to it in the specified direction.
from manim_extensions import MathTexLine
line = MathTexLine(MathTex("y = x"), direction=UP, color=BLUE)
Parameters
formula—MathTexformula objectdirection— Direction of the formula relative to the line, defaultUPbuff— Spacing between formula and line, default0.5**kwargs— Other arguments passed toLine
MathTexBrace(target, formula, direction=UP, buff=0.5, **kwargs)
Creates a brace for a target object and places a MathTex formula next to it.
from manim_extensions import MathTexBrace
line = Line(LEFT, RIGHT)
brace = MathTexBrace(line, MathTex("\\Delta x"), direction=UP)
Parameters
target— The object to be bracedformula—MathTexformula objectdirection— Direction of the brace relative to the target, defaultUPbuff— Spacing between formula and brace, default0.5**kwargs— Other arguments passed toBrace
MathTexDoublearrow(formula, direction=UP, buff=0.5, **kwargs)
Creates a double arrow and places a MathTex formula next to it in the specified direction.
from manim_extensions import MathTexDoublearrow
arrow = MathTexDoublearrow(MathTex("\\Leftrightarrow"), direction=DOWN)
Parameters
formula—MathTexformula objectdirection— Direction of the formula relative to the arrow, defaultUPbuff— Spacing between formula and arrow, default0.5**kwargs— Other arguments passed toDoubleArrow
ExtendedLine(line, extend_distance, **kwargs)
Extends an existing Line by a specified distance at both ends along its original direction.
from manim_extensions import ExtendedLine
original = Line(LEFT, RIGHT)
extended = ExtendedLine(original, extend_distance=1.0, color=RED)
Parameters
line— Original line segmentextend_distance— Distance to extend at each end**kwargs— Other arguments passed toLine
geometry Module
CircleInt(circle1, circle2)
Calculates the intersection points of two circles.
from manim_extensions import CircleInt
c1 = Circle(radius=2).shift(LEFT)
c2 = Circle(radius=2).shift(RIGHT)
result = CircleInt(c1, c2) # ([x1, y1, 0], [x2, y2, 0]) or None
Returns
- A tuple of two intersection points
([x, y, 0], [x, y, 0])if they intersect Noneif they do not intersect
LineCircleInt(line, circle)
Calculates the intersection points of a line segment and a circle, returning only points within the segment parameter range [0, 1].
from manim_extensions import LineCircleInt
line = Line(LEFT * 3, RIGHT * 3)
circle = Circle(radius=1)
result = LineCircleInt(line, circle)
Returns
- Two intersection points, one intersection point, or
None
LineInt(line1, line2)
Calculates the intersection point of two infinitely extended line segments in 2D (not restricted to the segment endpoints).
from manim_extensions import LineInt
l1 = Line(LEFT, RIGHT)
l2 = Line(DOWN, UP)
result = LineInt(l1, l2) # [0.0, 0.0, 0] or None
Returns
- Intersection point
[x, y, 0], orNoneif parallel
LineArcInt(line, arc)
Calculates the intersection points of a line segment and an arc, checking whether the points truly lie within the arc's angle range.
from manim_extensions import LineArcInt
line = Line(LEFT, RIGHT)
arc = Arc(start_angle=0, angle=PI, radius=1)
result = LineArcInt(line, arc)
Returns
- Two intersection points, one intersection point, or
None
TangentPoint(p1, p2, line_start, line_end)
Calculates the tangent point of a circle (passing through p1 and p2) and a line segment.
from manim_extensions import TangentPoint
p = TangentPoint(
[1, 0, 0], [-1, 0, 0],
line_start=[0, -2, 0], line_end=[0, 2, 0]
)
Parameters
p1,p2— Two points on the circle, in the format(x, y)or(x, y, z)line_start,line_end— Start and end points of the line segment
Returns
- Tangent point coordinates as
np.ndarray, orNoneif calculation fails
animations Module
VisDrawArc(scene, arc, axis=OUT, run_time=1)
Visualized arc drawing animation, showing a moving dot and a dashed radius line. Call it directly; no need to wrap it in self.play().
from manim_extensions import VisDrawArc
class MyScene(Scene):
def construct(self):
arc = Arc(start_angle=0, angle=PI, radius=2)
VisDrawArc(self, arc, axis=OUT, run_time=2)
Parameters
scene— Manim scene objectarc— TheArcto drawaxis— Rotation direction,OUTfor counterclockwise andINfor clockwise, defaultOUTrun_time— Animation duration in seconds, default1
TypeWriter(mobject, interval=2, **kwargs)
Typewriter effect animation that displays Text content character by character. Automatically calculates the total animation duration based on character count and interval.
from manim_extensions import TypeWriter
class MyScene(Scene):
def construct(self):
text = Text("Hello World")
self.play(TypeWriter(text, interval=0.1))
Parameters
mobject—Textobjectinterval— Display interval between characters in seconds, default2**kwargs— Other arguments passed toAnimation
License
MIT License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file manim_extensions-1.0.2.tar.gz.
File metadata
- Download URL: manim_extensions-1.0.2.tar.gz
- Upload date:
- Size: 19.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d3f40cabad6f7cd1bbe398e0b76bdc4151649d516d39d0ac6e5a26a366d41cfd
|
|
| MD5 |
c90941efdb9c8bbc1a5db64fccb61e73
|
|
| BLAKE2b-256 |
56c90ec4192178fdbf34fa485d3d24bc50e807841d45e80c86faee530dd7d2f8
|
File details
Details for the file manim_extensions-1.0.2-py3-none-any.whl.
File metadata
- Download URL: manim_extensions-1.0.2-py3-none-any.whl
- Upload date:
- Size: 14.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0b95c71d63a22dea6c7038f783fc5fb26c30e87499779d4a27711e9cfdf9e38b
|
|
| MD5 |
c543141d9bd32e6e2a6ab187ed5b05eb
|
|
| BLAKE2b-256 |
26d5ba643049cd1cb0404066c4aa767ab93ca6b8f049451a5c7965c650f10e8c
|