manim-extensions 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- manim_extensions-1.0.0/PKG-INFO +586 -0
- manim_extensions-1.0.0/README.md +559 -0
- manim_extensions-1.0.0/manim_extensions/__init__.py +3 -0
- manim_extensions-1.0.0/manim_extensions/animations.py +123 -0
- manim_extensions-1.0.0/manim_extensions/geometry.py +342 -0
- manim_extensions-1.0.0/manim_extensions/mobjects.py +193 -0
- manim_extensions-1.0.0/manim_extensions.egg-info/PKG-INFO +586 -0
- manim_extensions-1.0.0/manim_extensions.egg-info/SOURCES.txt +14 -0
- manim_extensions-1.0.0/manim_extensions.egg-info/dependency_links.txt +1 -0
- manim_extensions-1.0.0/manim_extensions.egg-info/requires.txt +4 -0
- manim_extensions-1.0.0/manim_extensions.egg-info/top_level.txt +1 -0
- manim_extensions-1.0.0/pyproject.toml +44 -0
- manim_extensions-1.0.0/setup.cfg +4 -0
- manim_extensions-1.0.0/tests/test_animations.py +22 -0
- manim_extensions-1.0.0/tests/test_geometry.py +122 -0
- manim_extensions-1.0.0/tests/test_mobjects.py +81 -0
|
@@ -0,0 +1,586 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: manim_extensions
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: A package for tools and extensions in Manim
|
|
5
|
+
Author-email: Zhu Chongjing <zhuchongjing_pypi@163.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/zhuchongjing/manim_extensions
|
|
8
|
+
Project-URL: Issues, https://github.com/zhuchongjing/manim_extensions/issues
|
|
9
|
+
Keywords: manim,animation,math,latex,geometry
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Intended Audience :: Education
|
|
12
|
+
Classifier: Intended Audience :: Science/Research
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
19
|
+
Classifier: Topic :: Multimedia :: Video
|
|
20
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
21
|
+
Classifier: Operating System :: OS Independent
|
|
22
|
+
Requires-Python: >=3.9
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
Requires-Dist: manim
|
|
25
|
+
Provides-Extra: dev
|
|
26
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
27
|
+
|
|
28
|
+
# manim_extensions
|
|
29
|
+
|
|
30
|
+
[English](#english) | [中文](#中文)
|
|
31
|
+
|
|
32
|
+
<a name="中文"></a>
|
|
33
|
+
## 中文
|
|
34
|
+
|
|
35
|
+
manim_extensions 是一个用于 [Manim](https://www.manim.community/) 的扩展工具包,提供了中文公式渲染、几何计算、带标注的图形以及常用动画效果,帮助你更高效地制作数学动画。
|
|
36
|
+
|
|
37
|
+
### 安装
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
pip install manim_extensions
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
依赖:`manim`
|
|
44
|
+
|
|
45
|
+
### 模块概览
|
|
46
|
+
|
|
47
|
+
| 模块 | 说明 |
|
|
48
|
+
|------|------|
|
|
49
|
+
| `mobjects` | Mobject 类扩展,包含中文公式、带标签圆点、可延长线段等 |
|
|
50
|
+
| `geometry` | 纯几何计算函数,用于求交点、切点等 |
|
|
51
|
+
| `animations` | 动画效果,如可视化绘弧、打字机效果 |
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
### mobjects 模块
|
|
56
|
+
|
|
57
|
+
#### `ChineseMathTex(*texts, font="SimSun", tex_to_color_map={}, **kwargs)`
|
|
58
|
+
|
|
59
|
+
支持中文显示的 `MathTex` 子类。可直接在公式中写入中文,无需手动包裹 `\text{}`。
|
|
60
|
+
|
|
61
|
+
```python
|
|
62
|
+
from manim_extensions import ChineseMathTex
|
|
63
|
+
|
|
64
|
+
formula = ChineseMathTex(
|
|
65
|
+
"\\frac{1}{2} + 你好 = x",
|
|
66
|
+
tex_to_color_map={"你好": RED},
|
|
67
|
+
font="SimSun"
|
|
68
|
+
)
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
**参数**
|
|
72
|
+
- `*texts` — LaTeX 文本字符串
|
|
73
|
+
- `font` — 中文字体名称,默认 `"SimSun"`
|
|
74
|
+
- `tex_to_color_map` — 文本到颜色的映射字典,默认 `{}`
|
|
75
|
+
- `**kwargs` — 传递给 `MathTex` 的其他参数
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
#### `LabelDot(dot_label, dot_pos, label_pos=DOWN, buff=0.1, **kwargs)`
|
|
80
|
+
|
|
81
|
+
在指定位置创建一个圆点,并在其旁边添加 `MathTex` 标签。
|
|
82
|
+
|
|
83
|
+
```python
|
|
84
|
+
from manim_extensions import LabelDot
|
|
85
|
+
|
|
86
|
+
dot = LabelDot("A", [1, 2, 0], label_pos=UP, buff=0.2)
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
**参数**
|
|
90
|
+
- `dot_label` — 标签文本
|
|
91
|
+
- `dot_pos` — 圆点位置
|
|
92
|
+
- `label_pos` — 标签相对圆点的方向,默认 `DOWN`
|
|
93
|
+
- `buff` — 标签与圆点的间距,默认 `0.1`
|
|
94
|
+
- `**kwargs` — 传递给 `VGroup` 的其他参数
|
|
95
|
+
|
|
96
|
+
---
|
|
97
|
+
|
|
98
|
+
#### `MathTexLine(formula, direction=UP, buff=0.5, **kwargs)`
|
|
99
|
+
|
|
100
|
+
创建一条线段,并在其指定方向旁放置 `MathTex` 公式。
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
from manim_extensions import MathTexLine
|
|
104
|
+
|
|
105
|
+
line = MathTexLine(MathTex("y = x"), direction=UP, color=BLUE)
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
**参数**
|
|
109
|
+
- `formula` — `MathTex` 公式对象
|
|
110
|
+
- `direction` — 公式相对线段的方向,默认 `UP`
|
|
111
|
+
- `buff` — 公式与线段的间距,默认 `0.5`
|
|
112
|
+
- `**kwargs` — 传递给 `Line` 的其他参数
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
#### `MathTexBrace(target, formula, direction=UP, buff=0.5, **kwargs)`
|
|
117
|
+
|
|
118
|
+
为指定对象创建一个花括号,并在其旁边放置 `MathTex` 公式。
|
|
119
|
+
|
|
120
|
+
```python
|
|
121
|
+
from manim_extensions import MathTexBrace
|
|
122
|
+
|
|
123
|
+
line = Line(LEFT, RIGHT)
|
|
124
|
+
brace = MathTexBrace(line, MathTex("\\Delta x"), direction=UP)
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
**参数**
|
|
128
|
+
- `target` — 要被花括号标注的目标对象
|
|
129
|
+
- `formula` — `MathTex` 公式对象
|
|
130
|
+
- `direction` — 公式与花括号相对目标的方向,默认 `UP`
|
|
131
|
+
- `buff` — 公式与花括号的间距,默认 `0.5`
|
|
132
|
+
- `**kwargs` — 传递给 `Brace` 的其他参数
|
|
133
|
+
|
|
134
|
+
---
|
|
135
|
+
|
|
136
|
+
#### `MathTexDoublearrow(formula, direction=UP, buff=0.5, **kwargs)`
|
|
137
|
+
|
|
138
|
+
创建一个双向箭头,并在其指定方向旁放置 `MathTex` 公式。
|
|
139
|
+
|
|
140
|
+
```python
|
|
141
|
+
from manim_extensions import MathTexDoublearrow
|
|
142
|
+
|
|
143
|
+
arrow = MathTexDoublearrow(MathTex("\\Leftrightarrow"), direction=DOWN)
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
**参数**
|
|
147
|
+
- `formula` — `MathTex` 公式对象
|
|
148
|
+
- `direction` — 公式相对箭头的方向,默认 `UP`
|
|
149
|
+
- `buff` — 公式与箭头的间距,默认 `0.5`
|
|
150
|
+
- `**kwargs` — 传递给 `DoubleArrow` 的其他参数
|
|
151
|
+
|
|
152
|
+
---
|
|
153
|
+
|
|
154
|
+
#### `ExtendedLine(line, extend_distance, **kwargs)`
|
|
155
|
+
|
|
156
|
+
基于一条已有的 `Line`,在其两端按原方向各延长指定距离。
|
|
157
|
+
|
|
158
|
+
```python
|
|
159
|
+
from manim_extensions import ExtendedLine
|
|
160
|
+
|
|
161
|
+
original = Line(LEFT, RIGHT)
|
|
162
|
+
extended = ExtendedLine(original, extend_distance=1.0, color=RED)
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
**参数**
|
|
166
|
+
- `line` — 原始线段
|
|
167
|
+
- `extend_distance` — 两端各延长的距离
|
|
168
|
+
- `**kwargs` — 传递给 `Line` 的其他参数
|
|
169
|
+
|
|
170
|
+
---
|
|
171
|
+
|
|
172
|
+
### geometry 模块
|
|
173
|
+
|
|
174
|
+
#### `CircleInt(circle1, circle2)`
|
|
175
|
+
|
|
176
|
+
计算两个圆的交点。
|
|
177
|
+
|
|
178
|
+
```python
|
|
179
|
+
from manim_extensions import CircleInt
|
|
180
|
+
|
|
181
|
+
c1 = Circle(radius=2).shift(LEFT)
|
|
182
|
+
c2 = Circle(radius=2).shift(RIGHT)
|
|
183
|
+
result = CircleInt(c1, c2) # ([x1, y1, 0], [x2, y2, 0]) 或 None
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
**返回**
|
|
187
|
+
- 若相交,返回两个交点坐标的元组 `([x, y, 0], [x, y, 0])`
|
|
188
|
+
- 若不相交,返回 `None`
|
|
189
|
+
|
|
190
|
+
---
|
|
191
|
+
|
|
192
|
+
#### `LineCircleInt(line, circle)`
|
|
193
|
+
|
|
194
|
+
计算线段与圆的交点,仅返回落在线段参数范围 `[0, 1]` 内的交点。
|
|
195
|
+
|
|
196
|
+
```python
|
|
197
|
+
from manim_extensions import LineCircleInt
|
|
198
|
+
|
|
199
|
+
line = Line(LEFT * 3, RIGHT * 3)
|
|
200
|
+
circle = Circle(radius=1)
|
|
201
|
+
result = LineCircleInt(line, circle)
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
**返回**
|
|
205
|
+
- 两个交点、一个交点,或 `None`
|
|
206
|
+
|
|
207
|
+
---
|
|
208
|
+
|
|
209
|
+
#### `LineInt(line1, line2)`
|
|
210
|
+
|
|
211
|
+
在二维平面上计算两条无限延长线段的交点(不限制在线段端点范围内)。
|
|
212
|
+
|
|
213
|
+
```python
|
|
214
|
+
from manim_extensions import LineInt
|
|
215
|
+
|
|
216
|
+
l1 = Line(LEFT, RIGHT)
|
|
217
|
+
l2 = Line(DOWN, UP)
|
|
218
|
+
result = LineInt(l1, l2) # [0.0, 0.0, 0] 或 None
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
**返回**
|
|
222
|
+
- 交点坐标 `[x, y, 0]`,或平行时返回 `None`
|
|
223
|
+
|
|
224
|
+
---
|
|
225
|
+
|
|
226
|
+
#### `LineArcInt(line, arc)`
|
|
227
|
+
|
|
228
|
+
计算线段与圆弧的交点,会检查交点是否真正落在圆弧的角度范围内。
|
|
229
|
+
|
|
230
|
+
```python
|
|
231
|
+
from manim_extensions import LineArcInt
|
|
232
|
+
|
|
233
|
+
line = Line(LEFT, RIGHT)
|
|
234
|
+
arc = Arc(start_angle=0, angle=PI, radius=1)
|
|
235
|
+
result = LineArcInt(line, arc)
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
**返回**
|
|
239
|
+
- 两个交点、一个交点,或 `None`
|
|
240
|
+
|
|
241
|
+
---
|
|
242
|
+
|
|
243
|
+
#### `TangentPoint(p1, p2, line_start, line_end)`
|
|
244
|
+
|
|
245
|
+
计算以 `p1` 和 `p2` 为圆上点、且与线段相切的切点坐标。
|
|
246
|
+
|
|
247
|
+
```python
|
|
248
|
+
from manim_extensions import TangentPoint
|
|
249
|
+
|
|
250
|
+
p = TangentPoint(
|
|
251
|
+
[1, 0, 0], [-1, 0, 0],
|
|
252
|
+
line_start=[0, -2, 0], line_end=[0, 2, 0]
|
|
253
|
+
)
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
**参数**
|
|
257
|
+
- `p1`, `p2` — 圆上的两个点,格式 `(x, y)` 或 `(x, y, z)`
|
|
258
|
+
- `line_start`, `line_end` — 线段的起点和终点
|
|
259
|
+
|
|
260
|
+
**返回**
|
|
261
|
+
- 切点坐标 `np.ndarray`,若无法计算则返回 `None`
|
|
262
|
+
|
|
263
|
+
---
|
|
264
|
+
|
|
265
|
+
### animations 模块
|
|
266
|
+
|
|
267
|
+
#### `VisDrawArc(scene, arc, axis=OUT, run_time=1)`
|
|
268
|
+
|
|
269
|
+
可视化绘制圆弧的动画,会同时显示一个沿圆弧移动的点及半径虚线。**直接调用即可,无需放入 `self.play()` 中。**
|
|
270
|
+
|
|
271
|
+
```python
|
|
272
|
+
from manim_extensions import VisDrawArc
|
|
273
|
+
|
|
274
|
+
class MyScene(Scene):
|
|
275
|
+
def construct(self):
|
|
276
|
+
arc = Arc(start_angle=0, angle=PI, radius=2)
|
|
277
|
+
VisDrawArc(self, arc, axis=OUT, run_time=2)
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
**参数**
|
|
281
|
+
- `scene` — Manim 场景对象
|
|
282
|
+
- `arc` — 要绘制的 `Arc`
|
|
283
|
+
- `axis` — 旋转方向,`OUT` 为逆时针,`IN` 为顺时针,默认 `OUT`
|
|
284
|
+
- `run_time` — 动画时长(秒),默认 `1`
|
|
285
|
+
|
|
286
|
+
---
|
|
287
|
+
|
|
288
|
+
#### `TypeWriter(mobject, interval=2, **kwargs)`
|
|
289
|
+
|
|
290
|
+
打字机效果动画,逐个字符显示 `Text` 对象的内容。自动根据字符数量与间隔计算动画总时长。
|
|
291
|
+
|
|
292
|
+
```python
|
|
293
|
+
from manim_extensions import TypeWriter
|
|
294
|
+
|
|
295
|
+
class MyScene(Scene):
|
|
296
|
+
def construct(self):
|
|
297
|
+
text = Text("Hello World")
|
|
298
|
+
self.play(TypeWriter(text, interval=0.1))
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
**参数**
|
|
302
|
+
- `mobject` — `Text` 对象
|
|
303
|
+
- `interval` — 字符间显示间隔(秒),默认 `2`
|
|
304
|
+
- `**kwargs` — 传递给 `Animation` 的其他参数
|
|
305
|
+
|
|
306
|
+
---
|
|
307
|
+
|
|
308
|
+
<a name="english"></a>
|
|
309
|
+
## English
|
|
310
|
+
|
|
311
|
+
manim_extensions is an extension toolkit for [Manim](https://www.manim.community/), providing Chinese formula rendering, geometric calculations, annotated graphics, and common animation effects to help you create mathematical animations more efficiently.
|
|
312
|
+
|
|
313
|
+
### Installation
|
|
314
|
+
|
|
315
|
+
```bash
|
|
316
|
+
pip install manim_extensions
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
Dependency: `manim`
|
|
320
|
+
|
|
321
|
+
### Module Overview
|
|
322
|
+
|
|
323
|
+
| Module | Description |
|
|
324
|
+
|--------|-------------|
|
|
325
|
+
| `mobjects` | Mobject class extensions, including Chinese formulas, labeled dots, extendable lines, etc. |
|
|
326
|
+
| `geometry` | Pure geometric calculation functions for finding intersections, tangent points, etc. |
|
|
327
|
+
| `animations` | Animation effects, such as visualized arc drawing and typewriter effects |
|
|
328
|
+
|
|
329
|
+
---
|
|
330
|
+
|
|
331
|
+
### mobjects Module
|
|
332
|
+
|
|
333
|
+
#### `ChineseMathTex(*texts, font="SimSun", tex_to_color_map={}, **kwargs)`
|
|
334
|
+
|
|
335
|
+
A `MathTex` subclass that supports Chinese characters. You can write Chinese directly in the formula without manually wrapping it in `\text{}`.
|
|
336
|
+
|
|
337
|
+
```python
|
|
338
|
+
from manim_extensions import ChineseMathTex
|
|
339
|
+
|
|
340
|
+
formula = ChineseMathTex(
|
|
341
|
+
"\\frac{1}{2} + 你好 = x",
|
|
342
|
+
tex_to_color_map={"你好": RED},
|
|
343
|
+
font="SimSun"
|
|
344
|
+
)
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
**Parameters**
|
|
348
|
+
- `*texts` — LaTeX text strings
|
|
349
|
+
- `font` — Chinese font name, default `"SimSun"`
|
|
350
|
+
- `tex_to_color_map` — Dictionary mapping text to colors, default `{}`
|
|
351
|
+
- `**kwargs` — Other arguments passed to `MathTex`
|
|
352
|
+
|
|
353
|
+
---
|
|
354
|
+
|
|
355
|
+
#### `LabelDot(dot_label, dot_pos, label_pos=DOWN, buff=0.1, **kwargs)`
|
|
356
|
+
|
|
357
|
+
Creates a dot at the specified position and adds a `MathTex` label next to it.
|
|
358
|
+
|
|
359
|
+
```python
|
|
360
|
+
from manim_extensions import LabelDot
|
|
361
|
+
|
|
362
|
+
dot = LabelDot("A", [1, 2, 0], label_pos=UP, buff=0.2)
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
**Parameters**
|
|
366
|
+
- `dot_label` — Label text
|
|
367
|
+
- `dot_pos` — Dot position
|
|
368
|
+
- `label_pos` — Direction of the label relative to the dot, default `DOWN`
|
|
369
|
+
- `buff` — Spacing between label and dot, default `0.1`
|
|
370
|
+
- `**kwargs` — Other arguments passed to `VGroup`
|
|
371
|
+
|
|
372
|
+
---
|
|
373
|
+
|
|
374
|
+
#### `MathTexLine(formula, direction=UP, buff=0.5, **kwargs)`
|
|
375
|
+
|
|
376
|
+
Creates a line segment and places a `MathTex` formula next to it in the specified direction.
|
|
377
|
+
|
|
378
|
+
```python
|
|
379
|
+
from manim_extensions import MathTexLine
|
|
380
|
+
|
|
381
|
+
line = MathTexLine(MathTex("y = x"), direction=UP, color=BLUE)
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
**Parameters**
|
|
385
|
+
- `formula` — `MathTex` formula object
|
|
386
|
+
- `direction` — Direction of the formula relative to the line, default `UP`
|
|
387
|
+
- `buff` — Spacing between formula and line, default `0.5`
|
|
388
|
+
- `**kwargs` — Other arguments passed to `Line`
|
|
389
|
+
|
|
390
|
+
---
|
|
391
|
+
|
|
392
|
+
#### `MathTexBrace(target, formula, direction=UP, buff=0.5, **kwargs)`
|
|
393
|
+
|
|
394
|
+
Creates a brace for a target object and places a `MathTex` formula next to it.
|
|
395
|
+
|
|
396
|
+
```python
|
|
397
|
+
from manim_extensions import MathTexBrace
|
|
398
|
+
|
|
399
|
+
line = Line(LEFT, RIGHT)
|
|
400
|
+
brace = MathTexBrace(line, MathTex("\\Delta x"), direction=UP)
|
|
401
|
+
```
|
|
402
|
+
|
|
403
|
+
**Parameters**
|
|
404
|
+
- `target` — The object to be braced
|
|
405
|
+
- `formula` — `MathTex` formula object
|
|
406
|
+
- `direction` — Direction of the brace relative to the target, default `UP`
|
|
407
|
+
- `buff` — Spacing between formula and brace, default `0.5`
|
|
408
|
+
- `**kwargs` — Other arguments passed to `Brace`
|
|
409
|
+
|
|
410
|
+
---
|
|
411
|
+
|
|
412
|
+
#### `MathTexDoublearrow(formula, direction=UP, buff=0.5, **kwargs)`
|
|
413
|
+
|
|
414
|
+
Creates a double arrow and places a `MathTex` formula next to it in the specified direction.
|
|
415
|
+
|
|
416
|
+
```python
|
|
417
|
+
from manim_extensions import MathTexDoublearrow
|
|
418
|
+
|
|
419
|
+
arrow = MathTexDoublearrow(MathTex("\\Leftrightarrow"), direction=DOWN)
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
**Parameters**
|
|
423
|
+
- `formula` — `MathTex` formula object
|
|
424
|
+
- `direction` — Direction of the formula relative to the arrow, default `UP`
|
|
425
|
+
- `buff` — Spacing between formula and arrow, default `0.5`
|
|
426
|
+
- `**kwargs` — Other arguments passed to `DoubleArrow`
|
|
427
|
+
|
|
428
|
+
---
|
|
429
|
+
|
|
430
|
+
#### `ExtendedLine(line, extend_distance, **kwargs)`
|
|
431
|
+
|
|
432
|
+
Extends an existing `Line` by a specified distance at both ends along its original direction.
|
|
433
|
+
|
|
434
|
+
```python
|
|
435
|
+
from manim_extensions import ExtendedLine
|
|
436
|
+
|
|
437
|
+
original = Line(LEFT, RIGHT)
|
|
438
|
+
extended = ExtendedLine(original, extend_distance=1.0, color=RED)
|
|
439
|
+
```
|
|
440
|
+
|
|
441
|
+
**Parameters**
|
|
442
|
+
- `line` — Original line segment
|
|
443
|
+
- `extend_distance` — Distance to extend at each end
|
|
444
|
+
- `**kwargs` — Other arguments passed to `Line`
|
|
445
|
+
|
|
446
|
+
---
|
|
447
|
+
|
|
448
|
+
### geometry Module
|
|
449
|
+
|
|
450
|
+
#### `CircleInt(circle1, circle2)`
|
|
451
|
+
|
|
452
|
+
Calculates the intersection points of two circles.
|
|
453
|
+
|
|
454
|
+
```python
|
|
455
|
+
from manim_extensions import CircleInt
|
|
456
|
+
|
|
457
|
+
c1 = Circle(radius=2).shift(LEFT)
|
|
458
|
+
c2 = Circle(radius=2).shift(RIGHT)
|
|
459
|
+
result = CircleInt(c1, c2) # ([x1, y1, 0], [x2, y2, 0]) or None
|
|
460
|
+
```
|
|
461
|
+
|
|
462
|
+
**Returns**
|
|
463
|
+
- A tuple of two intersection points `([x, y, 0], [x, y, 0])` if they intersect
|
|
464
|
+
- `None` if they do not intersect
|
|
465
|
+
|
|
466
|
+
---
|
|
467
|
+
|
|
468
|
+
#### `LineCircleInt(line, circle)`
|
|
469
|
+
|
|
470
|
+
Calculates the intersection points of a line segment and a circle, returning only points within the segment parameter range `[0, 1]`.
|
|
471
|
+
|
|
472
|
+
```python
|
|
473
|
+
from manim_extensions import LineCircleInt
|
|
474
|
+
|
|
475
|
+
line = Line(LEFT * 3, RIGHT * 3)
|
|
476
|
+
circle = Circle(radius=1)
|
|
477
|
+
result = LineCircleInt(line, circle)
|
|
478
|
+
```
|
|
479
|
+
|
|
480
|
+
**Returns**
|
|
481
|
+
- Two intersection points, one intersection point, or `None`
|
|
482
|
+
|
|
483
|
+
---
|
|
484
|
+
|
|
485
|
+
#### `LineInt(line1, line2)`
|
|
486
|
+
|
|
487
|
+
Calculates the intersection point of two infinitely extended line segments in 2D (not restricted to the segment endpoints).
|
|
488
|
+
|
|
489
|
+
```python
|
|
490
|
+
from manim_extensions import LineInt
|
|
491
|
+
|
|
492
|
+
l1 = Line(LEFT, RIGHT)
|
|
493
|
+
l2 = Line(DOWN, UP)
|
|
494
|
+
result = LineInt(l1, l2) # [0.0, 0.0, 0] or None
|
|
495
|
+
```
|
|
496
|
+
|
|
497
|
+
**Returns**
|
|
498
|
+
- Intersection point `[x, y, 0]`, or `None` if parallel
|
|
499
|
+
|
|
500
|
+
---
|
|
501
|
+
|
|
502
|
+
#### `LineArcInt(line, arc)`
|
|
503
|
+
|
|
504
|
+
Calculates the intersection points of a line segment and an arc, checking whether the points truly lie within the arc's angle range.
|
|
505
|
+
|
|
506
|
+
```python
|
|
507
|
+
from manim_extensions import LineArcInt
|
|
508
|
+
|
|
509
|
+
line = Line(LEFT, RIGHT)
|
|
510
|
+
arc = Arc(start_angle=0, angle=PI, radius=1)
|
|
511
|
+
result = LineArcInt(line, arc)
|
|
512
|
+
```
|
|
513
|
+
|
|
514
|
+
**Returns**
|
|
515
|
+
- Two intersection points, one intersection point, or `None`
|
|
516
|
+
|
|
517
|
+
---
|
|
518
|
+
|
|
519
|
+
#### `TangentPoint(p1, p2, line_start, line_end)`
|
|
520
|
+
|
|
521
|
+
Calculates the tangent point of a circle (passing through `p1` and `p2`) and a line segment.
|
|
522
|
+
|
|
523
|
+
```python
|
|
524
|
+
from manim_extensions import TangentPoint
|
|
525
|
+
|
|
526
|
+
p = TangentPoint(
|
|
527
|
+
[1, 0, 0], [-1, 0, 0],
|
|
528
|
+
line_start=[0, -2, 0], line_end=[0, 2, 0]
|
|
529
|
+
)
|
|
530
|
+
```
|
|
531
|
+
|
|
532
|
+
**Parameters**
|
|
533
|
+
- `p1`, `p2` — Two points on the circle, in the format `(x, y)` or `(x, y, z)`
|
|
534
|
+
- `line_start`, `line_end` — Start and end points of the line segment
|
|
535
|
+
|
|
536
|
+
**Returns**
|
|
537
|
+
- Tangent point coordinates as `np.ndarray`, or `None` if calculation fails
|
|
538
|
+
|
|
539
|
+
---
|
|
540
|
+
|
|
541
|
+
### animations Module
|
|
542
|
+
|
|
543
|
+
#### `VisDrawArc(scene, arc, axis=OUT, run_time=1)`
|
|
544
|
+
|
|
545
|
+
Visualized arc drawing animation, showing a moving dot and a dashed radius line. **Call it directly; no need to wrap it in `self.play()`.**
|
|
546
|
+
|
|
547
|
+
```python
|
|
548
|
+
from manim_extensions import VisDrawArc
|
|
549
|
+
|
|
550
|
+
class MyScene(Scene):
|
|
551
|
+
def construct(self):
|
|
552
|
+
arc = Arc(start_angle=0, angle=PI, radius=2)
|
|
553
|
+
VisDrawArc(self, arc, axis=OUT, run_time=2)
|
|
554
|
+
```
|
|
555
|
+
|
|
556
|
+
**Parameters**
|
|
557
|
+
- `scene` — Manim scene object
|
|
558
|
+
- `arc` — The `Arc` to draw
|
|
559
|
+
- `axis` — Rotation direction, `OUT` for counterclockwise and `IN` for clockwise, default `OUT`
|
|
560
|
+
- `run_time` — Animation duration in seconds, default `1`
|
|
561
|
+
|
|
562
|
+
---
|
|
563
|
+
|
|
564
|
+
#### `TypeWriter(mobject, interval=2, **kwargs)`
|
|
565
|
+
|
|
566
|
+
Typewriter effect animation that displays `Text` content character by character. Automatically calculates the total animation duration based on character count and interval.
|
|
567
|
+
|
|
568
|
+
```python
|
|
569
|
+
from manim_extensions import TypeWriter
|
|
570
|
+
|
|
571
|
+
class MyScene(Scene):
|
|
572
|
+
def construct(self):
|
|
573
|
+
text = Text("Hello World")
|
|
574
|
+
self.play(TypeWriter(text, interval=0.1))
|
|
575
|
+
```
|
|
576
|
+
|
|
577
|
+
**Parameters**
|
|
578
|
+
- `mobject` — `Text` object
|
|
579
|
+
- `interval` — Display interval between characters in seconds, default `2`
|
|
580
|
+
- `**kwargs` — Other arguments passed to `Animation`
|
|
581
|
+
|
|
582
|
+
---
|
|
583
|
+
|
|
584
|
+
## License
|
|
585
|
+
|
|
586
|
+
MIT License
|