File indexing completed on 2026-04-09 07:48:49
0001
0002 """
0003 pvprim.py
0004 =============
0005
0006 https://docs.pyvista.org/examples/00-load/create-geometric-objects.html
0007 """
0008
0009 import numpy as np
0010 import pyvista as pv
0011
0012 _white = "ffffff"
0013 _red = "ff0000"
0014 _green = "00ff00"
0015 _blue = "0000ff"
0016
0017 DTYPE = np.float64
0018 SIZE = np.array([1280, 720])
0019
0020
0021 """
0022 Rotation about Y transforms X axis to Z axis::
0023
0024
0025 Z X
0026 | Y | Y
0027 | / | /
0028 |/ |/
0029 +----- X Z -----+
0030
0031
0032 """
0033
0034
0035
0036 x2z = np.array(
0037 [[ 0., 0., -1., 0],
0038 [ 0., 1., 0., 0],
0039 [ 1., 0., 0., 0],
0040 [ 0., 0., 0., 0]] )
0041
0042
0043 if __name__ == '__main__':
0044
0045
0046 pl = pv.Plotter(window_size=SIZE*2, shape=(3,3) )
0047
0048 cyl = pv.Cylinder(direction=(0,0,1))
0049 arrow = pv.Arrow(direction=(0,0,1))
0050 cone = pv.Cone(direction=(0,0,1))
0051
0052 sphere = pv.Sphere()
0053 plane = pv.Plane()
0054 line = pv.Line()
0055 box = pv.Box()
0056 poly = pv.Polygon()
0057 disc = pv.Disc()
0058
0059 pl.subplot(0, 0)
0060 pl.add_mesh(cyl, color=_red, show_edges=True)
0061 pl.show_grid()
0062
0063 pl.subplot(0, 1)
0064 pl.add_mesh(arrow, color=_green, show_edges=True)
0065 pl.show_grid()
0066
0067 pl.subplot(0, 2)
0068 pl.add_mesh(sphere, color=_blue, show_edges=True)
0069 pl.show_grid()
0070
0071
0072 pl.subplot(1, 0)
0073 pl.add_mesh(plane, color="tan", show_edges=True)
0074 pl.show_grid()
0075
0076 pl.subplot(1, 1)
0077 pl.add_mesh(line, color="tan", line_width=3)
0078 pl.show_grid()
0079
0080 pl.subplot(1, 2)
0081 pl.add_mesh(box, color="tan", show_edges=True)
0082 pl.show_grid()
0083
0084
0085 pl.subplot(2, 0)
0086 pl.add_mesh(cone, color="tan", show_edges=True)
0087 pl.show_grid()
0088
0089 pl.subplot(2, 1)
0090 pl.add_mesh(poly, color="tan", show_edges=True)
0091 pl.show_grid()
0092
0093 pl.subplot(2, 2)
0094 pl.add_mesh(disc, color="tan", show_edges=True)
0095 pl.show_grid()
0096
0097 cp = pl.show()
0098 print(cp)
0099
0100
0101