3D码农建模 - 正多面体

在三维形状中,正多面体指各面都是全等的正多边形且每一个顶点所接的面数都是一样的凸多面体,符合这种特性的立体总共有5种: 正四面体, 正六面体, 正八面体, 正十二面体, 和正二十面体。

以下Python代码给出了在Blender 4中实现这些正多面体的方法,其中正六面体和正二十面体使用Blender基本形状实现,其它的则计算各个顶点的坐标然后连点成面以构造三维形状。

正四面体, 每面都是正三角形

Python 复制代码
def tetrahedron():
  edge_length = 4

  a = edge_length / (2.0 * math.sqrt(2.0))
  verts = [
      ( a,  a,  a),
      ( a, -a, -a),
      (-a,  a, -a),
      (-a, -a,  a),
  ]

  faces = [[0,1,2],[0,2,3],[0,3,1],[1,3,2]]

  mesh = bpy.data.meshes.new('mesh_tetrahedron')
  obj  = bpy.data.objects.new('tetrahedron', mesh)
  bpy.context.collection.objects.link(obj)

  mesh.from_pydata(verts, [], faces)
  mesh.update(calc_edges=True)

正六面体, 每面都是正四边形

Python 复制代码
def cube():
  ledge_length = 4

  bpy.ops.mesh.primitive_cube_add(
    size = ledge_length
  )

正八面体, 每面都是正三角形

Python 复制代码
def octahedron():
  ledge_length = 4
  a = ledge_length/sqrt(2)

  verts = [
    (a, 0, 0),
    (-a, 0, 0),
    (0, a, 0),
    (0, -a, 0),
    (0, 0, a),
    (0, 0, -a)
  ]

  faces = [[4,0,2],[4,2,1],[4,1,3],[4,3,0],[5,2,0],[5,1,2],[5,3,1],[5,0,3]]
  
  mesh = bpy.data.meshes.new('mesh_octahedron')
  obj  = bpy.data.objects.new('octahedron', mesh)
  bpy.context.collection.objects.link(obj)

  mesh.from_pydata(verts, [], faces)
  mesh.update(calc_edges=True)

正十二面体, 每面都是正五边形

Python 复制代码
def dodecahedron():
  ledge_length = 4

  golden_ratio = (1 + sqrt(5)) / 2

  s = ledge_length * golden_ratio / 2
  t = s / golden_ratio
  u = s * golden_ratio

  verts = [(s,s,s),(s,s,-s),(s,-s,s),(s,-s,-s),(-s,s,s),(-s,s,-s),(-s,-s,s),(-s,-s,-s),
             (t,u,0),(-t,u,0),(t,-u,0),(-t,-u,0),(u,0,t),(u,0,-t),(-u,0,t),(-u,0,-t),(0,t,u),
             (0,-t,u),(0,t,-u),(0,-t,-u)]

  faces = [[0,8,9,4,16],[0,12,13,1,8],[0,16,17,2,12],[8,1,18,5,9],[12,2,10,3,13],
            [16,4,14,6,17],[9,5,15,14,4],[6,11,10,2,17],[3,19,18,1,13],[7,15,5,18,19],
            [7,11,6,14,15],[7,19,3,10,11]]

  mesh = bpy.data.meshes.new('mesh_dodecahedron')
  obj  = bpy.data.objects.new('dodecahedron', mesh)
  bpy.context.collection.objects.link(obj)

  mesh.from_pydata(verts, [], faces)
  mesh.update(calc_edges=True)

正二十面体, 每面都是正三角形

Python 复制代码
def icosahedron():
  edge_length = 4

  bpy.ops.mesh.primitive_ico_sphere_add(
    radius = (edge_length / 4) * sqrt(10 + 2 * sqrt(5)),
    subdivisions = 1
  )
相关推荐
HelloGitHub15 分钟前
经过 10 亿级性能验证的隐私计算开源利器
python·开源·github
一号言安27 分钟前
牛客python蓝桥杯11-32(自用)
开发语言·python
梦丶晓羽31 分钟前
自然语言处理:主题模型
人工智能·python·自然语言处理·lda·主题模型
weixin_525936331 小时前
Python数据分析之机器学习基础
python·机器学习·数据分析
apcipot_rain1 小时前
【密码学——基础理论与应用】李子臣编著 第三章 分组密码 课后习题
python·算法·密码学
慕丹1 小时前
项目工坊 | Python驱动淘宝信息爬虫
爬虫·python·selenium
萌小丹Fighting5 小时前
【Python爬虫】使用python脚本拉取网页指定小说章节
爬虫·python
python布道者05165 小时前
【爬虫软件】抖音评论区采集工具
python
OreoCC7 小时前
第N5周:Pytorch文本分类入门
人工智能·pytorch·python
zimoyin9 小时前
解决 Java/Kotlin 资源加载问题
java·python·kotlin