python繪制直線的方法
更新時間:2018年06月30日 10:18:23 作者:genispan
這篇文章主要為大家詳細介紹了python繪制直線的方法,繪制直線通用方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了python繪制直線的具體代碼,供大家參考,具體內(nèi)容如下
#!/usr/bin/env python import vtk # 繪制通用方法 def myshow(linepolydata): # Now we'll look at it. lineMapper = vtk.vtkPolyDataMapper() if vtk.VTK_MAJOR_VERSION <= 5: lineMapper.SetInput(linepolydata) else: lineMapper.SetInputData(linepolydata) lineMapper.SetScalarRange(0, 2) lineActor = vtk.vtkActor() lineActor.SetMapper(lineMapper) # The usual rendering stuff. camera = vtk.vtkCamera() camera.SetPosition(1, 1, 1) camera.SetFocalPoint(0, 0, 0) renderer = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(renderer) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) renderer.AddActor(lineActor) renderer.SetActiveCamera(camera) renderer.ResetCamera() renderer.SetBackground(0, 0, 0) renWin.SetSize(300, 300) # interact with data renWin.Render() iren.Start() del lineMapper del lineActor del camera del renderer del renWin del iren def main(): # 直線在三維坐標系中的2個頂點 x = [(0.0, 0.0, 0.0),(1.0, 0.0, 0.0), (0.0, 1.0, 0.0)] # We'll create the building blocks of polydata including data attributes. linepoly = vtk.vtkPolyData() points = vtk.vtkPoints() lines = vtk.vtkCellArray() scalars = vtk.vtkFloatArray() for i in range(3): points.InsertNextPoint(x[i]) linepoly.SetPoints(points) line0 = vtk.vtkLine() line0.GetPointIds().SetId(0, 0); # 第二個0表示pts中的origin點 line0.GetPointIds().SetId(1, 1); # 第二個1表示pts中的p0點 line1 = vtk.vtkLine() line1.GetPointIds().SetId(0, 0); line1.GetPointIds().SetId(1, 2); lines.InsertNextCell(line0) lines.InsertNextCell(line1) linepoly.SetLines(lines); colors = vtk.vtkUnsignedCharArray() colors.SetNumberOfComponents(3); red = [255, 0, 0] colors.InsertNextTypedTuple(red); green = [0, 255, 0] colors.InsertNextTypedTuple(green); linepoly.GetCellData().SetScalars(colors); del points del lines del scalars del colors myshow(linepoly) # Clean up del linepoly main()

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
pytorch中實現(xiàn)彩色圖像(三通道)轉(zhuǎn)灰度圖像(單通道)
這篇文章主要介紹了pytorch中實現(xiàn)彩色圖像(三通道)轉(zhuǎn)灰度圖像(單通道),具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-02-02
python基于三階貝塞爾曲線的數(shù)據(jù)平滑算法
這篇文章主要介紹了python基于三階貝塞爾曲線的數(shù)據(jù)平滑算法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2019-12-12
Python實現(xiàn)雙軸組合圖表柱狀圖和折線圖的具體流程
這篇文章主要介紹了Python雙軸組合圖表柱狀圖+折線圖,Python繪制雙軸組合的關(guān)鍵在plt庫的twinx()函數(shù),具體實例代碼跟隨小編一起看看吧2021-08-08
關(guān)于pandas.date_range()的用法及說明
這篇文章主要介紹了關(guān)于pandas.date_range()的用法及說明,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-07-07
sklearn-SVC實現(xiàn)與類參數(shù)詳解
今天小編就為大家分享一篇sklearn-SVC實現(xiàn)與類參數(shù)詳解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-12-12

