You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Manim中实现√x绕X轴旋转生成抛物面?

用Manim实现√x绕X轴旋转的抛物面

方法一:直接使用ParametricSurface定义旋转曲面

绕X轴旋转时,原函数y=√x上的点(x, y)旋转后会形成以X轴为中心、半径y的圆,对应的3D参数方程可定义为:

  • x = u(u取值范围设为[0,4],可根据需求调整)
  • y = √u * cosθ
  • z = √u * sinθ(θ为旋转角度,范围[0, 2π])

直接用ParametricSurface实现的代码如下:

from manim import *

class RotatedParaboloid(ThreeDScene):
    def construct(self):
        # 设置3D相机视角
        self.set_camera_orientation(phi=75 * DEGREES, theta=30 * DEGREES)
        
        # 定义旋转抛物面
        paraboloid = ParametricSurface(
            lambda u, v: np.array([
                u,
                np.sqrt(u) * np.cos(v),
                np.sqrt(u) * np.sin(v)
            ]),
            u_range=[0, 4],
            v_range=[0, 2 * PI],
            resolution=(20, 30),  # 数值越大曲面越精细
            color=BLUE,
            opacity=0.7
        )
        
        # 添加原曲线作为参考
        original_curve = ParametricFunction(
            lambda t: np.array([t, np.sqrt(t), 0]),
            t_range=[0, 4],
            color=RED,
            stroke_width=4
        )
        
        self.add(original_curve, paraboloid)
        self.wait()

方法二:生成旋转曲线副本构建曲面

如果要通过“生成所有旋转过程的曲线副本”来模拟曲面,可以创建多个原曲线的副本,分别绕X轴旋转不同角度后组合成组,代码如下:

from manim import *

class ParaboloidFromCurves(ThreeDScene):
    def construct(self):
        self.set_camera_orientation(phi=75 * DEGREES, theta=30 * DEGREES)
        
        # 绘制原曲线y=√x
        original_curve = ParametricFunction(
            lambda t: np.array([t, np.sqrt(t), 0]),
            t_range=[0, 4],
            color=RED,
            stroke_width=4
        )
        self.add(original_curve)
        
        # 生成多个旋转后的曲线副本
        curve_group = VGroup()
        num_curves = 30  # 曲线数量越多,视觉效果越接近曲面
        for angle in np.linspace(0, 2 * PI, num_curves, endpoint=False):
            rotated_curve = original_curve.copy()
            rotated_curve.rotate(angle, axis=X_AXIS)
            rotated_curve.set_color(BLUE)
            rotated_curve.set_stroke_width(2)
            curve_group.add(rotated_curve)
        
        # 动画展示曲线生成过程
        self.play(Create(curve_group), run_time=3)
        self.wait()
  • 方法一适合直接生成光滑的旋转曲面,是Manim中3D曲面的标准实现方式。
  • 方法二更直观展示“旋转生成曲面”的过程,通过密集的曲线组合近似曲面效果。

内容的提问来源于stack exchange,提问作者SirMrpirateroberts

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.18 21:23:22