# How to generate a cylinder from an irregular polygon

**URL:** https://discourse.vtk.org/t/how-to-generate-a-cylinder-from-an-irregular-polygon/10362
**Category:** Support
**Tags:** python
**Created:** [January 3, 2023, 1:52am UTC](https://discourse.vtk.org/t/how-to-generate-a-cylinder-from-an-irregular-polygon/10362 "2023-01-03T01:52:24Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Dwight98](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dwight98/32/5373_2.png) [@Dwight98](https://discourse.vtk.org/u/Dwight98)
#### Post date: [January 3, 2023, 1:52am UTC](https://discourse.vtk.org/t/how-to-generate-a-cylinder-from-an-irregular-polygon/10362/1 "2023-01-03T01:52:24Z")

</div>

I want to turn an irregular polygon into a plane through VTK, and then stretch this plane vertically into an irregular cylinder，there are any good ways？I hope that the seniors will give good advice，Sincere thanks！

---

<div class="post-metadata">

### Author: ![will.schroeder](https://discourse.vtk.org/user_avatar/discourse.vtk.org/will.schroeder/32/233_2.png) [@will.schroeder](https://discourse.vtk.org/u/will.schroeder)
#### Post date: [January 3, 2023, 12:28pm UTC](https://discourse.vtk.org/t/how-to-generate-a-cylinder-from-an-irregular-polygon/10362/2 "2023-01-03T12:28:43Z")

</div>

Try Filters/Modeling/vtkLinearExtrusionFilter

---

<div class="post-metadata">

### Author: ![Dwight98](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dwight98/32/5373_2.png) [@Dwight98](https://discourse.vtk.org/u/Dwight98)
#### Post date: [January 4, 2023, 5:30pm UTC](https://discourse.vtk.org/t/how-to-generate-a-cylinder-from-an-irregular-polygon/10362/3 "2023-01-04T17:30:48Z")

</div>

thank you very much sir，it’s very useful for me

---- Replied Message ----

> From | [Will Schroeder via VTK](mailto:noreply@discourse.vtk.org)[noreply@discourse.vtk.org](mailto:noreply@discourse.vtk.org) |
> 
> - | - |  
> Date | 01/03/2023 20:29 |  
> To | [wlsc1998@163.com](mailto:wlsc1998@163.com)[wlsc1998@163.com](mailto:wlsc1998@163.com) |  
> Cc | |  
> Subject | [VTK] [Support] How to generate a cylinder from an irregular polygon |

> ![](https://discourse.vtk.org/user_avatar/discourse.vtk.org/will.schroeder/45/233_2.png "will.schroeder") | [Will Schroeder](https://discourse.vtk.org/u/will.schroeder) will.schroeder  
> January 3 |
> 
> - | - |

Try Filters/Modeling/vtkLinearExtrusionFilter

---

<div class="post-metadata">

### Author: ![Dwight98](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dwight98/32/5373_2.png) [@Dwight98](https://discourse.vtk.org/u/Dwight98)
#### Post date: [January 12, 2023, 8:32am UTC](https://discourse.vtk.org/t/how-to-generate-a-cylinder-from-an-irregular-polygon/10362/4 "2023-01-12T08:32:08Z")

</div>

Dear seniors，Take the liberty to bother you again，Based on your previous description, I can use vtkLinearExtrusionFilter to generate the model I want，but，A problem arose with this process，I used two objects, vtkPoints and vtkCellArray, to generate the required polygons, but the parameter value I gave vtkpoints was established by the latitude and longitude in the WGS84 coordinate system，so I can’t export the correct obj model，How should I do。Not sure if my expression is cleared，But below is my code, I hope you can give me a little advice, thank you very much

import vtk

def main():  
points = vtk.vtkPoints()

```
points.InsertPoint(0, 2.0, 1.0, 0.0)
points.InsertPoint(1, 1.0, 1.0, 0.0)
points.InsertPoint(2, 1.0, 2.0, 0.0)
points.InsertPoint(3, -1.0, 2.0, 0.0)
points.InsertPoint(4, -1.0, -1.0, 0.0)
points.InsertPoint(5, 2.0, -1.0, 0.0)

print(points)
print(points.GetNumberOfPoints())
poly = vtk.vtkCellArray()

poly.InsertNextCell(6)
poly.InsertCellPoint(0)
poly.InsertCellPoint(1)
poly.InsertCellPoint(2)
poly.InsertCellPoint(3)
poly.InsertCellPoint(4)
poly.InsertCellPoint(5)

profile = vtk.vtkPolyData()
profile.SetPoints(points)
profile.SetPolys(poly)

normals = vtk.vtkPolyDataNormals() 
normals.SetInputData(profile)
normals.SetComputeCellNormals(1)
normals.SetComputePointNormals(0)
normals.SetFeatureAngle(60)  
normals.Update()
cellNormals = normals.GetOutput().GetCellData().GetNormals()

for item in range(cellNormals.GetNumberOfTuples()):
    value = [0,0,0]
    cellNormals.GetTuple(item,value)
    print(value[0],value[1],value[2])
# print(normals.GetOutput().GetCellData().GetNormals().GetTuple(0,[0,0,0]))

extrude = vtk.vtkLinearExtrusionFilter()
extrude.SetInputData(profile)
extrude.SetVector(value[0],value[1],value[2])
extrude.SetScaleFactor(10)
extrude.Update()

mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(extrude.GetOutputPort())
spring = vtk.vtkActor()
spring.SetMapper(mapper)
spring.GetProperty().SetColor(0.0, 0.79, 0.34)
ren = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
iren.SetInteractorStyle(vtk.vtkInteractorStyleTrackballCamera())
ren.AddActor(spring)
renWin.Render()
iren.Start()

```

if **name** == ‘ **main** ’:  
main()

---

<div class="post-metadata">

### Author: ![Dwight98](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dwight98/32/5373_2.png) [@Dwight98](https://discourse.vtk.org/u/Dwight98)
#### Post date: [January 12, 2023, 8:33am UTC](https://discourse.vtk.org/t/how-to-generate-a-cylinder-from-an-irregular-polygon/10362/5 "2023-01-12T08:33:48Z")

</div>

What needs to be added to you:The code I posted above is an example，The parameter I actually inserted is some latitude and longitude values，I’m sorry I didn’t notice until after I uploaded my response
