# Hexahedron

vtk-examples/Python/GeometricObjects/Hexahedron

### Description¶

The hexahedron is a primary three-dimensional cell consisting of six quadrilateral faces, twelve edges, and eight vertices. The hexahedron is defined by an ordered list of eight points. The faces and edges must not intersect any other faces and edges, and the hexahedron must be convex.

Other languages

See (Cxx), (CSharp)

Question

### Code¶

Hexahedron.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import vtk

def main():
colors = vtk.vtkNamedColors()

# Set the background color.
colors.SetColor("BkgColor", [51, 77, 102, 255])

# For the hexahedron setup the coordinates of eight points.
# The two faces must be in counter clockwise order as viewed from the
# outside.
pointCoordinates = list()
pointCoordinates.append([0.0, 0.0, 0.0])  # Face 1
pointCoordinates.append([1.0, 0.0, 0.0])
pointCoordinates.append([1.0, 1.0, 0.0])
pointCoordinates.append([0.0, 1.0, 0.0])
pointCoordinates.append([0.0, 0.0, 1.0])  # Face 2
pointCoordinates.append([1.0, 0.0, 1.0])
pointCoordinates.append([1.0, 1.0, 1.0])
pointCoordinates.append([0.0, 1.0, 1.0])

# Create the points.
points = vtk.vtkPoints()

# Create a hexahedron from the points.
hexahedron = vtk.vtkHexahedron()

for i in range(0, len(pointCoordinates)):
points.InsertNextPoint(pointCoordinates[i])
hexahedron.GetPointIds().SetId(i, i)

# Add the hexahedron to a cell array.
hexs = vtk.vtkCellArray()
hexs.InsertNextCell(hexahedron)

# Add the points and hexahedron to an unstructured grid.
uGrid = vtk.vtkUnstructuredGrid()
uGrid.SetPoints(points)
uGrid.InsertNextCell(hexahedron.GetCellType(), hexahedron.GetPointIds())

# Visualize.
mapper = vtk.vtkDataSetMapper()
mapper.SetInputData(uGrid)

actor = vtk.vtkActor()
actor.GetProperty().SetColor(colors.GetColor3d("PeachPuff"))
actor.SetMapper(mapper)

renderer = vtk.vtkRenderer()
renderWindow = vtk.vtkRenderWindow()
renderWindow.SetWindowName("Hexahedron")
renderWindowInteractor = vtk.vtkRenderWindowInteractor()
renderWindowInteractor.SetRenderWindow(renderWindow)