Filling area Or geting area under the Surface using ManimCE

44 views Asked by At

I want Plot this figure by using ManimCE the equation of the surface of the given imageImage is Sin[x+y^2]. I Want to plot similler figure in ManimCE. I Plot this figure using wolfram mathemaitca. Mathematica code given following -

Plot3D[Sin[x + y^2], {x, -2, 2}, {y, -2, 2}, 
   RegionFunction -> (#1^2 + #2^2 < 4 &), Filling -> Bottom, 
   FillingStyle -> Directive[Opacity[0.4], Red]]
1

There are 1 answers

1
AgnostMystic On
from manim import *

class SinXYPlot3D(ThreeDScene): def construct(self): axes = ThreeDAxes( x_range=[-2, 2, 0.5], y_range=[-2, 2, 0.5], z_range=[-1, 1, 0.5], x_length=7, y_length=7, z_length=4 )

    def func(x, y):
        return np.sin(x + y**2)
    
    def condition(x, y):
        return x**2 + y**2 < 4

    surface = Surface(
        lambda u, v: axes.c2p(u, v, func(u, v)),
        u_range=[-2, 2],
        v_range=[-2, 2],
        checkerboard_colors=[BLUE_D, BLUE_E],
        resolution=(50, 50)
    ).set_opacity(0.5)  # Set the opacity for the filling effect

    # Filter out the parts of the surface that don't meet the condition
    surface_filtered = Surface(
        lambda u, v: axes.c2p(u, v, func(u, v) if condition(u, v) else np.nan),
        u_range=[-2, 2],
        v_range=[-2, 2],
        checkerboard_colors=[BLUE_D, BLUE_E],
        resolution=(50, 50)
    ).set_opacity(0.5)

    self.set_camera_orientation(phi=75 * DEGREES, theta=30 * DEGREES)
    self.add(axes, surface_filtered)
    self.wait()