ManimCommunity / ManimCommunity/manim

Feature Request: Add ImplicitSurface for visualizing f(x, y, z) = 0

Open
#4,428 3 comments 0 reactions 0 assignees View on GitHub
new feature
Dominant language
Python
Stars
40.9k
Forks
3.1k
Avg merge
3d 12h
Merged PRs (30d)
25

Description

### Description of the problem
ManimCE supports Surface and ParametricSurface for explicit and parametric surfaces.
However, there is no built-in way to visualize implicit surfaces defined by an equation of the form:

$$f(x,y,z) = 0$$

### I have an idea:

```python
from manim import *
import numpy as np
from skimage import measure

def ImplicitSurface(f, x_range, y_range, z_range):
X, Y, Z = np.mgrid[
x_range[0]:x_range[1]:x_range[2]*1j,
y_range[0]:y_range[1]:y_range[2]*1j,
z_range[0]:z_range[1]:z_range[2]*1j
]

dx = (x_range[1] - x_range[0]) / (x_range[2] - 1)
dy = (y_range[1] - y_range[0]) / (y_range[2] - 1)
dz = (z_range[1] - z_range[0]) / (z_range[2] - 1)

verts, faces, _, _ = measure.marching_cubes(f(X, Y, Z), level=0, spacing=(dx, dy, dz))
verts[:,0] += x_range[0]
verts[:,1] += y_range[0]
verts[:,2] += z_range[0]

return VGroup(*[Polygon(*verts[i], stroke_width=0.5, fill_opacity=1) for i in faces]).set_shade_in_3d(True)

class MyScene(ThreeDScene):
def construct(self):
self.set_camera_orientation(phi=60*DEGREES, theta=-60*DEGREES)
surface = ImplicitSurface(
f=lambda x, y, z: x**4 + y**4 + z**4 -16*(x**2 + y**2 + z**2) + 120,
x_range=[-4.1, 4.1, 50],
y_range=[-4.1, 4.1, 50],
z_range=[-4.1, 4.1, 50],
).set_color_by_gradient(RED, PINK)

self.add(surface.scale(0.6))

Contributor guide

Open the contributing guide

Research direction

Start by reading the existing Surface and ParametricSurface entry points. The issue provides a marching-cubes example using NumPy and skimage; use it to understand the proposed inputs and output. Done should be a built-in ImplicitSurface that can visualize the supplied f(x,y,z)=0 example in a ThreeDScene.

Written by the indexing model from the issue text.

Assessment

Tech stack
numpy, python
Domain
computer-graphics
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.