在Manim中制作3D管状体动画无显示,疑与Difference参数有关
问题解决:Manim 3D管状体无法显示的修复
你的代码问题出在3D对象的布尔运算方法错误,Difference是Manim为2D图形设计的差集工具,不适用于3D模型。需要改用CSG(构造实体几何)接口来实现3D布尔运算。
修复后的代码
from manim import * class Tube(ThreeDScene): def construct(self): # 创建圆柱并转换为CSG对象,用于3D布尔运算 outer = Cylinder(radius=2, height=4, direction=OUT, fill_opacity=0.7, color=BLUE).to_csg() inner = Cylinder(radius=1, height=4, direction=OUT, fill_opacity=1, color=BLACK).to_csg() # 通过CSG的subtract方法实现差集,得到管状体 tube = outer.subtract(inner) self.set_camera_orientation(phi=75 * DEGREES, theta=30 * DEGREES) self.add(tube) self.wait(2)
关键修改点
- 将两个
Cylinder对象通过.to_csg()转换为CSG实例,这是Manim处理3D布尔运算的标准方式 - 用
outer.subtract(inner)替代Difference(outer, inner),完成3D模型的差集计算 - 保留原有的相机视角设置,确保能正确观察3D管状体
内容的提问来源于stack exchange,提问作者zakariya marzouk
相关产品推荐
相关产品推荐

