Skip to content

Commit f9dc9c7

Browse files
xyzqmJasonGrace2282pre-commit-ci[bot]
authored
Update documentation and typings for ParametricFunction (#3703)
* Update documentation and typings for ParametricFunction * Use manim tyings Co-authored-by: adeshpande <[email protected]> * fix typings * a few doc fixes * Update manim/mobject/graphing/functions.py Co-authored-by: adeshpande <[email protected]> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * update typings * remove extraneous line * update example code * add line back for comptibility * import TYPE_CHECKING --------- Co-authored-by: adeshpande <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 5139765 commit f9dc9c7

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

manim/mobject/graphing/functions.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
__all__ = ["ParametricFunction", "FunctionGraph", "ImplicitFunction"]
66

77

8-
from typing import Callable, Iterable, Sequence
8+
from typing import TYPE_CHECKING, Callable, Iterable, Sequence
99

1010
import numpy as np
1111
from isosurfaces import plot_isoline
@@ -14,6 +14,10 @@
1414
from manim.mobject.graphing.scale import LinearBase, _ScaleBase
1515
from manim.mobject.opengl.opengl_compatibility import ConvertToOpenGL
1616
from manim.mobject.types.vectorized_mobject import VMobject
17+
18+
if TYPE_CHECKING:
19+
from manim.typing import Point2D, Point3D
20+
1721
from manim.utils.color import YELLOW
1822

1923

@@ -23,9 +27,9 @@ class ParametricFunction(VMobject, metaclass=ConvertToOpenGL):
2327
Parameters
2428
----------
2529
function
26-
The function to be plotted in the form of ``(lambda x: x**2)``
30+
The function to be plotted in the form of ``(lambda t: (x(t), y(t), z(t)))``
2731
t_range
28-
Determines the length that the function spans. By default ``[0, 1]``
32+
Determines the length that the function spans in the form of (t_min, t_max, step=0.01). By default ``[0, 1]``
2933
scaling
3034
Scaling class applied to the points of the function. Default of :class:`~.LinearBase`.
3135
use_smoothing
@@ -49,10 +53,10 @@ class ParametricFunction(VMobject, metaclass=ConvertToOpenGL):
4953
5054
class PlotParametricFunction(Scene):
5155
def func(self, t):
52-
return np.array((np.sin(2 * t), np.sin(3 * t), 0))
56+
return (np.sin(2 * t), np.sin(3 * t), 0)
5357
5458
def construct(self):
55-
func = ParametricFunction(self.func, t_range = np.array([0, TAU]), fill_opacity=0).set_color(RED)
59+
func = ParametricFunction(self.func, t_range = (0, TAU), fill_opacity=0).set_color(RED)
5660
self.add(func.scale(3))
5761
5862
.. manim:: ThreeDParametricSpring
@@ -61,11 +65,11 @@ def construct(self):
6165
class ThreeDParametricSpring(ThreeDScene):
6266
def construct(self):
6367
curve1 = ParametricFunction(
64-
lambda u: np.array([
68+
lambda u: (
6569
1.2 * np.cos(u),
6670
1.2 * np.sin(u),
6771
u * 0.05
68-
]), color=RED, t_range = np.array([-3*TAU, 5*TAU, 0.01])
72+
), color=RED, t_range = (-3*TAU, 5*TAU, 0.01)
6973
).set_shade_in_3d(True)
7074
axes = ThreeDAxes()
7175
self.add(axes, curve1)
@@ -97,8 +101,8 @@ def construct(self):
97101

98102
def __init__(
99103
self,
100-
function: Callable[[float, float], float],
101-
t_range: Sequence[float] | None = None,
104+
function: Callable[[float], Point3D],
105+
t_range: Point2D | Point3D = (0, 1),
102106
scaling: _ScaleBase = LinearBase(),
103107
dt: float = 1e-8,
104108
discontinuities: Iterable[float] | None = None,
@@ -107,7 +111,7 @@ def __init__(
107111
**kwargs,
108112
):
109113
self.function = function
110-
t_range = [0, 1, 0.01] if t_range is None else t_range
114+
t_range = (0, 1, 0.01) if t_range is None else t_range
111115
if len(t_range) == 2:
112116
t_range = np.array([*t_range, 0.01])
113117

0 commit comments

Comments
 (0)