A community-maintained Python framework for creating mathematical animations.
Added documentation for discontinuous functions (#2279)
icedcoffeeeea8f52809f7ac
diff --git a/manim/mobject/functions.py b/manim/mobject/functions.pyindex f5b06698a..8e20a320d 100644--- a/manim/mobject/functions.py+++ b/manim/mobject/functions.py@@ -30,6 +30,10 @@ class ParametricFunction(VMobject, metaclass=ConvertToOpenGL):use_smoothingWhether to interpolate between the points of the function after they have been created.(Will have odd behaviour with a low number of points)+ discontinuities+ Values of t at which the function experiences discontinuity.+ dt+ The left and right tolerance for the discontinuities.Examples@@ -62,6 +66,28 @@ class ParametricFunction(VMobject, metaclass=ConvertToOpenGL):self.add(axes, curve1)self.set_camera_orientation(phi=80 * DEGREES, theta=-60 * DEGREES)self.wait()++ .. attention::+ If your function has discontinuities, you'll have to specify the location+ of the discontinuities manually. See the following example for guidance.++ .. manim:: DiscontinuousExample+ :save_last_frame:++ class DiscontinuousExample(Scene):+ def construct(self):+ ax1 = NumberPlane((-3, 3), (-4, 4))+ ax2 = NumberPlane((-3, 3), (-4, 4))+ VGroup(ax1, ax2).arrange()+ discontinuous_function = lambda x: (x ** 2 - 2) / (x ** 2 - 4)+ incorrect = ax1.plot(discontinuous_function, color=RED)+ correct = ax2.plot(+ discontinuous_function,+ discontinuities=[-2, 2], # discontinuous points+ dt=0.1, # left and right tolerance of discontinuity+ color=GREEN,+ )+ self.add(ax1, ax2, incorrect, correct)"""def __init__(@@ -82,7 +108,7 @@ class ParametricFunction(VMobject, metaclass=ConvertToOpenGL):self.scaling = scalingself.dt = dt- self.discontinuities = [] if discontinuities is None else discontinuities+ self.discontinuities = discontinuitiesself.use_smoothing = use_smoothingself.t_min, self.t_max, self.t_step = t_range@@ -96,7 +122,7 @@ class ParametricFunction(VMobject, metaclass=ConvertToOpenGL):def generate_points(self):- if self.discontinuities:+ if self.discontinuities is not None:discontinuities = filter(lambda t: self.t_min <= t <= self.t_max,self.discontinuities,