Skip to content

Conversation

@jakekinchen
Copy link
Contributor

@jakekinchen jakekinchen commented Dec 2, 2025

Summary

This PR introduces a new ImplicitSurface mobject that enables visualization of 3D surfaces defined by implicit functions f(x, y, z) = 0, analogous to how ImplicitFunction handles 2D implicit curves.

Key Features

  • Marching cubes algorithm via PyMCubes library for high-quality mesh extraction
  • Lightweight dependency: PyMCubes is only ~50-300KB (vs scikit-image's 22MB)
  • Configurable resolution parameter for mesh density control
  • High accuracy: Mean vertex error < 0.001 for unit sphere, axis intercepts at ±0.998
  • Dual renderer support: Works with both Cairo and OpenGL renderers
  • Verification method: verify_surface() for accuracy validation

New Dependency

  • pymcubes>=0.1.0 - Fast, lightweight marching cubes implementation

Example Usage

from manim import *

class ImplicitSphereExample(ThreeDScene):
    def construct(self):
        def sphere_func(x, y, z):
            return x**2 + y**2 + z**2 - 1.0

        surface = ImplicitSurface(
            sphere_func,
            x_range=(-1.3, 1.3),
            y_range=(-1.3, 1.3),
            z_range=(-1.3, 1.3),
            resolution=40,
            fill_color=BLUE,
            fill_opacity=0.8,
        )

        self.set_camera_orientation(phi=70 * DEGREES, theta=-45 * DEGREES)
        self.add(surface)

Rendered Examples

Sphere (unit sphere with 3D axes):
sphere_test0000

Torus (major radius 2, minor radius 0.5):
torus_test0000

Gyroid (minimal surface with salmon-to-pink gradient):
gyroid_test0000

manim -ql example_scenes/implicit_surface_examples.py ImplicitSphereExample
manim -ql example_scenes/implicit_surface_examples.py ImplicitGyroidExample

Files Changed

  • manim/mobject/three_d/implicit_surface.py - Main implementation
  • manim/mobject/opengl/opengl_implicit_surface.py - OpenGL renderer support
  • tests/module/mobject/test_implicit_surface.py - 10 unit tests
  • tests/test_graphical_units/test_threed.py - Graphical regression tests
  • example_scenes/implicit_surface_examples.py - 6 example scenes
  • pyproject.toml - Added pymcubes dependency

Test Plan

  • All 10 unit tests pass (pytest tests/module/mobject/test_implicit_surface.py)
  • Vertex accuracy verified (mean radius error 0.0005 for unit sphere)
  • Axis intersection points correctly positioned (±0.998 for unit sphere)
  • Linting passes (ruff check)
  • Renders correctly with Cairo renderer
  • CI tests pass
  • Documentation builds correctly

Related

  • Similar to ImplicitFunction for 2D curves
  • Complements existing Surface class for parametric surfaces

Introduces a new ImplicitSurface mobject that visualizes 3D surfaces
defined by implicit functions f(x, y, z) = 0, similar to how
ImplicitFunction handles 2D implicit curves.

Features:
- Uses PyMCubes library for marching cubes mesh extraction (~50-300KB)
- Configurable resolution parameter for mesh density control
- High vertex accuracy (mean error < 0.001 for unit sphere)
- Supports both Cairo and OpenGL renderers
- Includes verify_surface() method for accuracy validation

New dependency: pymcubes>=0.1.0

Includes unit tests, graphical tests, and example scenes demonstrating
spheres, tori, gyroids, and other implicit surfaces.
pre-commit-ci bot and others added 7 commits December 2, 2025 18:39
The ImplicitSurface functionality is already covered by unit tests
in tests/module/mobject/test_implicit_surface.py
- Add proper type annotations to __init__ and method signatures
- Remove unused type: ignore comments
- Fix return types to match parent class signatures
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 🆕 New

Development

Successfully merging this pull request may close these issues.

1 participant