Skip to content
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

Artifacts/false discontinuities in ImplicitFunction #2177

Open
Darylgolden opened this issue Oct 10, 2021 · 2 comments
Open

Artifacts/false discontinuities in ImplicitFunction #2177

Darylgolden opened this issue Oct 10, 2021 · 2 comments
Labels
issue:bug Something isn't working... For use in issues

Comments

@Darylgolden
Copy link
Member

Darylgolden commented Oct 10, 2021

Description of bug / unexpected behavior

Looking closely at the output from ImplicitFunction you'd often see many false discontinuities. For example, if you look closely at the example from the docs, you'd see many points where the curve breaks.

In this example:

class ImplicitFunctionDemo(Scene):
    def construct(self):
        plane = NumberPlane()
        curve = ImplicitFunction(
            lambda x, y: (x**2 + y**2)**2 - 42*(x**2 - y**2),
            color=YELLOW,
            max_quads=10000,
        )
        self.add(plane)
        self.add(curve)

even with 10000 quads, discontinuities can still be seen:

implicitbug

Expected behavior

How to reproduce the issue

Code for reproducing the problem
Paste your code here.

Additional media files

Images/GIFs

Logs

Terminal output
PASTE HERE OR PROVIDE LINK TO https://pastebin.com/ OR SIMILAR

System specifications

System Details
  • OS (with version, e.g Windows 10 v2004 or macOS 10.15 (Catalina)):
  • RAM:
  • Python version (python/py/python3 --version):
  • Installed modules (provide output from pip list):
PASTE HERE
LaTeX details
  • LaTeX distribution (e.g. TeX Live 2020):
  • Installed LaTeX packages:
FFMPEG

Output of ffmpeg -version:

PASTE HERE

Additional comments

@Darylgolden Darylgolden added the issue:bug Something isn't working... For use in issues label Oct 10, 2021
@Darylgolden
Copy link
Member Author

Pinging @jared-hughes as the author of isocontours.

@jared-hughes
Copy link
Contributor

There are two issues here:

Smoothing

Somehow, smoothing can make the curves discontinuous. This is a bug with Manim. This can be "fixed" for implicit functions by changing the default of use_smoothing to false, but it may reveal a deeper bug with smoothing.

In the following example, I confirmed that this is computed as one curve (with 509 points)

class ImplicitFunctionDemo(Scene):
    def construct(self):
        plane = NumberPlane()
        curve = always_redraw(
            lambda: ImplicitFunction(
                lambda x, y: (x ** 2 + y ** 2) ** 2 - 42 * (x ** 2 - y ** 2),
                color=YELLOW,
                max_quads=1000,
                use_smoothing=True,
            )
        )
        self.add(plane)
        self.add(curve)

Also note the strange appearance near (0,0):

ImplicitFunctionDemo_ManimCE_v0 11 0

Contrast this with the same code except with use_smoothing=False:

ImplicitFunctionDemo_ManimCE_v0 11 0

Contours near the boundaries of the region

Some triangles near the edges are not utilized in computation of the curve. This really only matters if max_quads is low, and it is a bug with isosurfaces.

image

class ImplicitFunctionDemo(Scene):
    def construct(self):
        plane = NumberPlane()
        k = ValueTracker(10)
        curve = always_redraw(
            lambda: ImplicitFunction(
                lambda x, y: (x ** 2 + y ** 2) ** 2 - k.get_value() * (x ** 2 - y ** 2),
                color=YELLOW,
                max_quads=100,
                min_depth=1,
                use_smoothing=False,
            )
        )
        self.add(plane)
        self.add(curve)
        self.play(k.animate.set_value(50), run_time=1)
ImplicitFunctionDemo.mp4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
issue:bug Something isn't working... For use in issues
Projects
Status: 🆕 New
Development

No branches or pull requests

2 participants