python繪制圓柱體的方法
更新時間:2018年07月02日 08:32:54 作者:genispan
這篇文章主要為大家詳細介紹了python繪制圓柱體的方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了python繪制圓柱體示的具體代碼,供大家參考,具體內容如下
#!/usr/bin/env python import vtk # 參考的C++版本源碼及解釋 感謝原作者 # http://blog.csdn.net/www_doling_net/article/details/8536376 def main(): cylinder = vtk.vtkCylinderSource() cylinder.SetHeight(3.0) # 設置柱體的高 cylinder.SetRadius(1.0) # 設置柱體橫截面的半徑 cylinder.SetResolution(6) # 設置柱體橫截面的等邊多邊形的邊數(shù) cylinderMapper = vtk.vtkPolyDataMapper() # 渲染多邊形幾何數(shù)據(jù) cylinderMapper.SetInputConnection(cylinder.GetOutputPort()) # VTK可視化管線的輸入數(shù)據(jù)接口 ,對應的可視化管線輸出數(shù)據(jù)的接口為GetOutputPort(); cylinderActor = vtk.vtkActor() cylinderActor.SetMapper(cylinderMapper) # 設置生成幾何圖元的Mapper。即連接一個Actor到可視化管線的末端(可視化管線的末端就是Mapper)。 renderer = vtk.vtkRenderer() # 負責管理場景的渲染過程 renderer.AddActor(cylinderActor) renderer.SetBackground(0.1, 0.2, 0.4) renWin = vtk.vtkRenderWindow() # 將操作系統(tǒng)與VTK渲染引擎連接到一起。 renWin.AddRenderer(renderer) renWin.SetSize(300, 300) iren = vtk.vtkRenderWindowInteractor() # 提供平臺獨立的響應鼠標、鍵盤和時鐘事件的交互機制 iren.SetRenderWindow(renWin) # 交互器樣式的一種,該樣式下,用戶是通過控制相機對物體作旋轉、放大、縮小等操作 style = vtk.vtkInteractorStyleTrackballCamera() iren.SetInteractorStyle(style) iren.Initialize() iren.Start() # Clean up del cylinder del cylinderMapper del cylinderActor del renderer del renWin del iren main()
效果圖:
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
Python標準庫之urllib和urllib3的使用及說明
這篇文章主要介紹了Python標準庫之urllib和urllib3使用及說明,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-12-12python將三維數(shù)組展開成二維數(shù)組的實現(xiàn)
今天小編就為大家分享一篇python將三維數(shù)組展開成二維數(shù)組的實現(xiàn),具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-11-11