python3dblendergrasshopper

Python: Create a polyhedron and get its section


I want to create a polyhedron by giving its coordinates, and then get a specific section. Maybe something like:

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. 

How can I do that? Is there any lib for that?

Here is what I find so far:

  1. Vpython is pretty what I need, but it seems too basic, and cannot create a polyhedron
  2. Blender and Rhino are good tools. But they focus more on modelling rather than programming. Python is more like a interactive commandline rather than a program itself.
  3. Three.js seems what I need, but js cannot perform scientific computation.

enter image description here


Solution

  • As a blender user my opinion is biased that way. Yes it focuses on being a gui tool for end users, but it deeply integrates python for defining the user interface all the way to adding features through python addons. It also includes a python console that lets you type in commands that alter data directly, allowing you to see changes in the 3dview. It is also possible to add extra python modules that can then be used within blender.

    Blender's python api can be read and searched online.

    You should find some examples to help create a polyhedron in the extra objects addon. It is included with blender so you can also find the scripts in your blender install.

    Maybe look into how the intersect tool works, you can call the intersect operator yourself, there is also a boolean modifier that may be better to get a closed mesh to calculate the volume.

    For calculating the volume there is BMesh.calc_volume, it is used by the 3d printing toolbox.

    You might want to add blender.stackexchange.com to your list to get blender specific python help.