# Cylinder

VTKExamples/Python/GeometricObjects/Cylinder

### Description¶

vtkCylinderSource object creates a polygonal cylinder centered at Center.

The axis of the cylinder is aligned along the global y-axis. The height and radius of the cylinder can be specified, as well as the number of sides.

It is also possible to control whether the cylinder is open-ended or capped. If you have the end points of the cylinder, you should use a vtkLineSource followed by a vtkTubeFilter instead of the vtkCylinderSource.

Other Languages

See (Cxx), (CSharp)

Question

### Code¶

Cylinder.py

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

import vtk

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

# Create a sphere
cylinderSource = vtk.vtkCylinderSource()
cylinderSource.SetCenter(0.0, 0.0, 0.0)
cylinderSource.SetHeight(7.0)
cylinderSource.SetResolution(100)

# Create a mapper and actor
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(cylinderSource.GetOutputPort())
actor = vtk.vtkActor()
actor.GetProperty().SetColor(colors.GetColor3d("Cornsilk"))
actor.SetMapper(mapper)

# Create a renderer, render window, and interactor
renderer = vtk.vtkRenderer()
renderWindow = vtk.vtkRenderWindow()
renderWindow.SetWindowName("Cylinder")
renderWindowInteractor = vtk.vtkRenderWindowInteractor()
renderWindowInteractor.SetRenderWindow(renderWindow)

# Add the actor to the scene