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
  )
相关推荐
2401_868534782 分钟前
农商行分布式网络建设
python·pygame
AC赳赳老秦1 小时前
OpenClaw 多源采集公开行业数据:从原始信息到研究报告初稿的自动化实践
java·c语言·c++·python·php·deepseek·openclaw
程序员雷欧1 小时前
AQS深度解析
开发语言·python
玩三国杀玩的1 小时前
Pytorch-c++-CUDA
c++·pytorch·python·深度学习
Albert Edison1 小时前
PyCharm 字体大小设置
ide·python·pycharm
叠层归一研究院1 小时前
如何用程序搭建一个 AGI 种子系统(一):从向量种子到无限生长引擎
人工智能·python·算法·机器学习·agi
l1258652 小时前
# RAG重排序实战:硅基流动bge-reranker-v2-m3在线API vs 本地CrossEncoder,一篇讲透两种方案
数据库·人工智能·python·深度学习·算法·机器学习·langchain
问天_观心3 小时前
零基础在windows环境下的WSL使用llamafactory(一)
人工智能·windows·python·神经网络·语言模型·github·模型蒸馏
今天你AiPy了吗3 小时前
AI桌面助手的隐私底线 数据可落本地不出域,还能一键切换云端,全能智能体
人工智能·python·ai·ai编程·智能体
2601_956319883 小时前
近期手工规则转量化:按学习、表达、开发、验证推进
人工智能·python