Search code examples
pythonmayavi

Mayavi Mlab : Drawing octahedrons


I cannot find a way to draw octahedrons. Could someone point me to a class for drawing triangular (transclucent) surfaces at the least?

tvtk.tools.visual seems to have only a few basic shapes.


Solution

  • The Gallery has an example of how to use triangular_mesh:

    import numpy as np
    import mayavi.mlab as ML
    
    verts = [(1,-1,0), (1,1,0), (-1,1,0), (-1,-1,0), (0,0,1), (0,0,-1)]
    x, y, z = zip(*verts)
    # Each triangle is a 3-tuple of indices. The indices are indices of `verts`.
    triangles = [(i, (i+1)%4, j) for i in range(4) for j in (4,5)]
    colorval = z
    ML.triangular_mesh(x, y, z, triangles, scalars=colorval, opacity=0.75)
    ML.show()
    

    enter image description here