Skip to content

Added documentation for discontinuous functions #2279

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Nov 29, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions manim/mobject/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ class ParametricFunction(VMobject, metaclass=ConvertToOpenGL):
use_smoothing
Whether 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
Expand Down Expand Up @@ -62,6 +66,28 @@ def construct(self):
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__(
Expand All @@ -82,7 +108,7 @@ def __init__(
self.scaling = scaling

self.dt = dt
self.discontinuities = [] if discontinuities is None else discontinuities
self.discontinuities = discontinuities
self.use_smoothing = use_smoothing
self.t_min, self.t_max, self.t_step = t_range

Expand All @@ -96,7 +122,7 @@ def get_point_from_function(self, t):

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,
Expand Down