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

Manim制作彩色莫比乌斯环出现首尾颜色差异的原因及解决方法

Manim制作莫比乌斯环首尾颜色不一致的成因与解决方法

成因分析

莫比乌斯环是典型的单侧曲面,当参数u从0遍历到2π时,曲面的法向量方向会完全翻转。而Manim的Surface类是基于面片的法向量计算光照亮度的,你设置的u_range=[0, 2*PI]让首尾的u值(0和2π)对应的法向量方向完全相反,最终导致光照下首尾区域呈现出明显的颜色差异,看起来像是“首尾颜色不一致”。

解决方法

方案1:微调u_range的上限

把u_range的上限设为略大于2π的值(比如2*PI + 0.01),让Manim自动处理首尾的过渡,消除法向量突变带来的颜色差。修改后的完整代码:

from manim import *

BG_COLOR = "#F7F5E7"

config.background_color = BG_COLOR


def mobius_func(u, v):
    x = (1 + v / 2 * np.cos(u / 2)) * np.cos(u)
    y = (1 + v / 2 * np.cos(u / 2)) * np.sin(u)
    z = v / 2 * np.sin(u / 2)
    return np.array((x, y, z))


class Logo(ThreeDScene):
    def construct(self):
        self.set_camera_orientation(
            phi=50 * DEGREES, theta=330 * DEGREES, run_time=2, zoom=2.2
        )

        mobius = Surface(
            mobius_func,
            u_range=[0, 2 * PI + 0.01],  # 扩展u的范围以覆盖过渡区域
            v_range=[-1, 1],
            resolution=(64, 16),
        )
        mobius.set_color(RED)
        self.add(mobius)

方案2:直接使用Manim内置的MöbiusStrip类

Manim已经内置了处理好的莫比乌斯环实现,无需手动编写参数化函数,能直接避免这类参数边界问题:

from manim import *

BG_COLOR = "#F7F5E7"

config.background_color = BG_COLOR


class Logo(ThreeDScene):
    def construct(self):
        self.set_camera_orientation(
            phi=50 * DEGREES, theta=330 * DEGREES, run_time=2, zoom=2.2
        )
        mobius = MöbiusStrip()
        mobius.set_color(RED)
        self.add(mobius)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.31 16:10:25