Python: 创建一个多面体并得到它的截面

Python: Create a polyhedron and get its section

我想通过给定坐标创建一个polyhedron,然后得到一个特定的部分。也许是这样的:

Points = [A(0,0,0),B(1,0,0),C(1,1,0),D(0,1,0),A"(0,0,1),B"(1,0,1),C"(1,1,1),D"(0,1,1)]
Body = BodyGenerate(Points)
section1 = Body.section(z = 0.5)
section2 = Body.section(x+y= 1)
#And then I can get properties like `area`, `width` of these sections. 

我该怎么做?有什么 lib 吗?

这是我目前的发现:

  1. Vpython 正是我所需要的,但它似乎太基础了,无法创建多面体
  2. BlenderRhino 是很好的工具。但他们更关注 modelling 而不是 programming。 Python 更像是一个交互式命令行而不是程序本身。
  3. Three.js好像是我需要的,但是js不能进行科学计算。

作为搅拌机用户,我的观点是有偏见的。是的,它专注于成为最终用户的 gui 工具,但它深入集成了 python 以定义用户界面,一直到通过 python 插件添加功能。它还包括一个 python 控制台,可让您输入直接更改数据的命令,从而在 3d 视图中查看更改。也可以添加额外的 python 模块,然后可以在 blender 中使用。

Blender 的 python api 可以是 read and searched online.

您应该在 extra objects addon 中找到一些示例来帮助创建多面体。它包含在搅拌机中,因此您也可以在搅拌机安装中找到脚本。

也许研究一下如何intersect tool works, you can call the intersect operator yourself, there is also a boolean modifier得到一个封闭的网格来计算体积可能会更好。

计算体积有BMesh.calc_volume, it is used by the 3d printing toolbox

您可能希望将 blender.stackexchange.com 添加到您的列表中以获得特定于搅拌机的 python 帮助。