日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python 3d库_深入了解python的3D高级库pyvista

發布時間:2024/1/1 python 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python 3d库_深入了解python的3D高级库pyvista 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1 說明:

=====

1.2 PyVista是VTK的Python高級API,國內基本沒有介紹和教程。

1.3 PyVista比VTK、pyqt5和pyside2都簡單,所以,有必要再次深入介紹。

2 生成gif并播放:

============

2.1 效果圖:

2.2 代碼:

#第1步:導入模塊

import pyvista as pvimport numpy as np#第2步:3維坐標點取值范圍

x = np.arange(-10, 10, 0.25)

y = np.arange(-10, 10, 0.25)

#meshgrid的作用適用于生成網格型數據#可以接受兩個一維數組生成兩個二維矩陣,對應兩個數組中所有的(x,y)對x, y = np.meshgrid(x, y)#np.sqrt(x) : 計算數組各元素的平方根

r = np.sqrt(x ** 2 + y ** 2)

#獲取z值z = np.sin(r)

# Create and structured surface

grid = pv.StructuredGrid(x, y, z)#第3步:產生plt圖:靜態圖和gif動態圖

# Create a plotter object and set the scalars to the Z height

plt = pv.Plotter()#加入上面產生的gridplt.add_mesh(grid, scalars=z.ravel())#先按q退出靜態圖,進入動態圖gif展示print('Orient the view, then press "q" to close window and produce movie')

# setup camera and close

plt.show(auto_close=False) #參數不能少#第4步:動態播放gif設置

# Open a gif,這個文件在根目錄下plt.open_gif("wave.gif")

#獲取點的參數pts = grid.points.copy()# Update Z and write a frame for each updated position

nframe = 30 #數值越大,動態展示時間越久

#[:nframe]是列表取值從0取到nframe個

for i in np.linspace(0, 2 * np.pi, nframe + 1)[:nframe]:

#z值改變 z = np.sin(r + i)

pts[:, -1] = z.ravel()

#根系 plt.update_coordinates(pts) plt.update_scalars(z.ravel()) plt.write_frame()# Close movie and delete object

plt.close()

3 球、線和圖例:

============

3.1 效果圖:

3.2 代碼:

import pyvista as pv

# Create source to ray tracesphere = pv.Sphere(radius=0.85)

# Define line segmentstart = [0, 0, 0]

stop = [0.25, 1, 0.5]

# Perform ray tracepoints, ind = sphere.ray_trace(start, stop)# Create geometry to represent ray traceray = pv.Line(start, stop)intersection = pv.PolyData(points)# Render the result,調用圖p = pv.Plotter()#添加元素mesh,顏色設定、大小和文字標簽(圖例展示)#添加球==spherep.add_mesh(sphere, show_edges=True, opacity=0.5, color="w",

lighting=False, label="Test Mesh")

#添加線==rayp.add_mesh(ray, color="blue", line_width=5, label="Ray Segment")

p.add_mesh(intersection, color="maroon",

point_size=25, label="Intersection Points")

#圖例展示p.add_legend()#圖片展示p.show()

4 布局subplot:

===========

4.1 效果圖:

4.2 重點:

#第3步:定義一個圖,展示圖,布局shape=3*3

#就是3行3列

p = pv.Plotter(shape=(3, 3))

4.3 完整代碼:

#第1步:導入模塊

import pyvista as pv

#第2步:實例化模型,調用模型

cyl = pv.Cylinder()arrow = pv.Arrow()sphere = pv.Sphere()plane = pv.Plane()line = pv.Line()box = pv.Box()

cone = pv.Cone()poly = pv.Polygon()disc = pv.Disc()#第3步:定義一個圖,展示圖,布局shape=3*3

#就是3行3列

p = pv.Plotter(shape=(3, 3))

# Top row==第1行

p.subplot(0, 0)

p.add_mesh(cyl, color="tan", show_edges=True)

p.subplot(0, 1)

p.add_mesh(arrow, color="tan", show_edges=True)

p.subplot(0, 2)

p.add_mesh(sphere, color="tan", show_edges=True)

# Middle row==第2行

p.subplot(1, 0)

p.add_mesh(plane, color="tan", show_edges=True)

p.subplot(1, 1)

p.add_mesh(line, color="tan", line_width=3)

p.subplot(1, 2)

p.add_mesh(box, color="tan", show_edges=True)

# Bottom row==第3行

p.subplot(2, 0)

p.add_mesh(cone, color="tan", show_edges=True)

p.subplot(2, 1)

p.add_mesh(poly, color="tan", show_edges=True)

p.subplot(2, 2)

p.add_mesh(disc, color="tan", show_edges=True)

# Render all of themp.show()

總結

以上是生活随笔為你收集整理的python 3d库_深入了解python的3D高级库pyvista的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。