填充区域或使用ManimCE获取表面下的区域

问题描述 投票:0回答:1

给定图像Image的表面方程为Sin[x+y^2]。我想在 ManimCE 中绘制类似的图形。我使用 Wolfram mathemaitca 绘制了这个图。 Mathematica 代码如下 -

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]]
python wolfram-mathematica manim algorithm-animation
1个回答
0
投票
from manim import *

类 SinXYPlot3D(ThreeDScene): def 构造(自身): 轴 = ThreeDAxes( x_range=[-2, 2, 0.5], y_range=[-2, 2, 0.5], z_range=[-1, 1, 0.5], x_长度=7, y_长度=7, z_长度=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()
© www.soinside.com 2019 - 2024. All rights reserved.