Geometric Objects 绘制预定义简单几何体对象
1 | import pyvista as pv |
1 2 3 4 5 6 7 8 9 | 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() |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | p = pv.Plotter(shape=(3, 3)) # Top row 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 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 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 them p.show() |

随机生成点云(100个点)
1 2 3 4 5 6 7 | import numpy as np import pyvista as pv nodes = np.random.rand(100, 3) print(nodes[0:5, :]) mesh = pv.PolyData(nodes) mesh.plot(point_size=10, screenshot='random_nodes.png') |
1 2 3 4 5 | [[0.92260997 0.40661435 0.57888308] [0.5247008 0.19672089 0.16145517] [0.8563844 0.01669512 0.36461162] [0.7026067 0.91075625 0.34128197] [0.19480557 0.61431345 0.81374728]] |
