Geometric ObjectsΒΆ
PyVista includes a few functions to generate simple geometric objects. The code documentation for these functions are on this page; to see what these functions create, check out the example: Geometric Objects.
-
pyvista.
Sphere
(radius=0.5, center=(0, 0, 0), direction=(0, 0, 1), theta_resolution=30, phi_resolution=30, start_theta=0, end_theta=360, start_phi=0, end_phi=180)ΒΆ Create a vtk Sphere.
- Parameters
radius (float, optional) β Sphere radius
center (np.ndarray or list, optional) β Center in [x, y, z]
direction (list or tuple or np.ndarray) β Direction the top of the sphere points to in [x, y, z]
theta_resolution (int , optional) β Set the number of points in the longitude direction (ranging from start_theta to end theta).
phi_resolution (int, optional) β Set the number of points in the latitude direction (ranging from start_phi to end_phi).
start_theta (float, optional) β Starting longitude angle.
end_theta (float, optional) β Ending longitude angle.
start_phi (float, optional) β Starting latitude angle.
end_phi (float, optional) β Ending latitude angle.
- Returns
sphere β Sphere mesh.
- Return type
-
pyvista.
Cylinder
(center=(0.0, 0.0, 0.0), direction=(1.0, 0.0, 0.0), radius=0.5, height=1.0, resolution=100, capping=True, **kwargs)ΒΆ Create the surface of a cylinder.
See also
pyvista.CylinderStructured()
.- Parameters
center (list or tuple or np.ndarray) β Location of the centroid in [x, y, z]
direction (list or tuple or np.ndarray) β Direction cylinder points to in [x, y, z]
radius (float) β Radius of the cylinder.
height (float) β Height of the cylinder.
resolution (int) β Number of points on the circular face of the cylinder.
capping (bool, optional) β Cap cylinder ends with polygons. Default True
- Returns
cylinder β Cylinder surface.
- Return type
Examples
>>> import pyvista >>> import numpy as np >>> cylinder = pyvista.Cylinder(np.array([1, 2, 3]), np.array([1, 1, 1]), 1, 1) >>> cylinder.plot()
-
pyvista.
CylinderStructured
(radius=0.5, height=1.0, center=(0.0, 0.0, 0.0), direction=(1.0, 0.0, 0.0), theta_resolution=32, z_resolution=10)ΒΆ Create a cylinder mesh as a
pyvista.StructuredGrid
.The end caps are left open. This can create a surface mesh if a single value for the
radius
is given or a 3D mesh if multiple radii are given as a list/array in theradius
argument.- Parameters
radius (float) β Radius of the cylinder. If an iterable
height (float) β Height (length) of the cylinder along its Z-axis
center (list or tuple or np.ndarray) β Location of the centroid in [x, y, z]
direction (list or tuple or np.ndarray) β Direction cylinder Z-axis in [x, y, z]
theta_resolution (int) β Number of points on the circular face of the cylinder.
z_resolution (int) β Number of points along the height (Z-axis) of the cylinder
-
pyvista.
Arrow
(start=(0.0, 0.0, 0.0), direction=(1.0, 0.0, 0.0), tip_length=0.25, tip_radius=0.1, tip_resolution=20, shaft_radius=0.05, shaft_resolution=20, scale=None)ΒΆ Create a vtk Arrow.
- Parameters
start (np.ndarray) β Start location in [x, y, z]
direction (list or tuple or np.ndarray) β Direction the arrow points to in [x, y, z]
tip_length (float, optional) β Length of the tip.
tip_radius (float, optional) β Radius of the tip.
tip_resolution (int, optional) β Number of faces around the tip.
shaft_radius (float, optional) β Radius of the shaft.
shaft_resolution (int, optional) β Number of faces around the shaft.
scale (float or str, optional) β Scale factor of the entire object, default is None (i.e. scale of 1). βautoβ scales to length of direction array.
- Returns
arrow β Arrow surface.
- Return type
-
pyvista.
Plane
(center=(0, 0, 0), direction=(0, 0, 1), i_size=1, j_size=1, i_resolution=10, j_resolution=10)ΒΆ Create a plane.
- Parameters
center (list or tuple or np.ndarray) β Location of the centroid in [x, y, z]
direction (list or tuple or np.ndarray) β Direction of the planeβs normal in [x, y, z]
i_size (float) β Size of the plane in the i direction.
j_size (float) β Size of the plane in the j direction.
i_resolution (int) β Number of points on the plane in the i direction.
j_resolution (int) β Number of points on the plane in the j direction.
- Returns
plane β Plane mesh
- Return type
-
pyvista.
Line
(pointa=(- 0.5, 0.0, 0.0), pointb=(0.5, 0.0, 0.0), resolution=1)ΒΆ Create a line.
- Parameters
pointa (np.ndarray or list) β Location in [x, y, z].
pointb (np.ndarray or list) β Location in [x, y, z].
resolution (int) β number of pieces to divide line into
-
pyvista.
Cube
(center=(0.0, 0.0, 0.0), x_length=1.0, y_length=1.0, z_length=1.0, bounds=None)ΒΆ Create a cube.
Itβs possible to specify either the center and side lengths or just the bounds of the cube. If
bounds
are given, all other arguments are ignored.- Parameters
center (np.ndarray or list) β Center in [x, y, z].
x_length (float) β length of the cube in the x-direction.
y_length (float) β length of the cube in the y-direction.
z_length (float) β length of the cube in the z-direction.
bounds (np.ndarray or list) β Specify the bounding box of the cube. If given, all other arguments are ignored.
(xMin,xMax, yMin,yMax, zMin,zMax)
-
pyvista.
Box
(bounds=(- 1.0, 1.0, - 1.0, 1.0, - 1.0, 1.0), level=0, quads=True)ΒΆ Create a box with solid faces for the given bounds.
- Parameters
bounds (np.ndarray or list) β Specify the bounding box of the cube.
(xMin, xMax, yMin, yMax, zMin, zMax)
level (int) β Level of subdivision of the faces.
quads (bool, optional) β Flag to tell the source to generate either a quad or two triangle for a set of four points. Default
True
.
-
pyvista.
Cone
(center=(0.0, 0.0, 0.0), direction=(1.0, 0.0, 0.0), height=1.0, radius=None, capping=True, angle=None, resolution=6)ΒΆ Create a cone.
- Parameters
center (np.ndarray or list) β Center in [x, y, z]. middle of the axis of the cone.
direction (np.ndarray or list) β Direction vector in [x, y, z]. orientation vector of the cone.
height (float) β Height along the cone in its specified direction.
radius (float) β Base radius of the cone
capping (bool) β Turn on/off whether to cap the base of the cone with a polygon.
angle (float) β The angle degrees between the axis of the cone and a generatrix.
resolution (int) β Number of facets used to represent the cone
-
pyvista.
Polygon
(center=(0.0, 0.0, 0.0), radius=1, normal=(0, 0, 1), n_sides=6)ΒΆ Create a polygonal disk with a hole in the center.
The disk has zero height. The user can specify the inner and outer radius of the disk, and the radial and circumferential resolution of the polygonal representation.
- Parameters
center (np.ndarray or list) β Center in [x, y, z]. middle of the axis of the polygon.
radius (float) β The radius of the polygon
normal (np.ndarray or list) β Direction vector in [x, y, z]. orientation vector of the cone.
n_sides (int) β Number of sides of the polygon
-
pyvista.
Disc
(center=(0.0, 0.0, 0.0), inner=0.25, outer=0.5, normal=(0, 0, 1), r_res=1, c_res=6)ΒΆ Create a polygonal disk with a hole in the center.
The disk has zero height. The user can specify the inner and outer radius of the disk, and the radial and circumferential resolution of the polygonal representation.
- Parameters
center (np.ndarray or list) β Center in [x, y, z]. middle of the axis of the disc.
inner (float) β The inner radius
outer (float) β The outer radius
normal (np.ndarray or list) β Direction vector in [x, y, z]. orientation vector of the cone.
r_res (int) β Number of points in radius direction.
r_res β Number of points in circumferential direction.
-
pyvista.
Text3D
(string, depth=0.5)ΒΆ Create 3D text from a string.
-
pyvista.
Spline
(points, n_points=None)ΒΆ Create a spline from points.
- Parameters
points (np.ndarray) β Array of points to build a spline out of. Array must be 3D and directionally ordered.
n_points (int, optional) β Number of points to interpolate along the points array.
- Returns
spline β Line mesh of spline.
- Return type
Examples
Construct a spline
>>> import numpy as np >>> import pyvista as pv >>> theta = np.linspace(-4 * np.pi, 4 * np.pi, 100) >>> z = np.linspace(-2, 2, 100) >>> r = z**2 + 1 >>> x = r * np.sin(theta) >>> y = r * np.cos(theta) >>> points = np.column_stack((x, y, z)) >>> spline = pv.Spline(points, 1000)
-
pyvista.
Wavelet
(extent=(- 10, 10, - 10, 10, - 10, 10), center=(0, 0, 0), maximum=255, x_freq=60, y_freq=30, z_freq=40, x_mag=10, y_mag=18, z_mag=5, std=0.5, subsample_rate=1)ΒΆ Create a wavelet.
-
pyvista.
CircularArc
(pointa, pointb, center, resolution=100, normal=None, polar=None, angle=None, negative=False)ΒΆ Create a circular arc defined by two endpoints and a center.
The number of segments composing the polyline is controlled by setting the object resolution. Alternatively, one can use a better API (that does not allow for inconsistent nor ambiguous inputs), using a starting point (polar vector, measured from the arcβs center), a normal to the plane of the arc, and an angle defining the arc length.
- Parameters
pointa (np.ndarray or list) β Position of the first end point.
pointb (np.ndarray or list) β Position of the other end point.
center (np.ndarray or list) β Center of the circle that defines the arc.
resolution (int, optional) β The number of segments of the polyline that draws the arc. Resolution of 1 will just create a line.
normal (np.ndarray or list) β The normal vector to the plane of the arc. By default it points in the positive Z direction.
polar (np.ndarray or list) β (starting point of the arc). By default it is the unit vector in the positive x direction. Note: This is only used when normal has been input.
angle (float) β Arc length (in degrees), beginning at the polar vector. The direction is counterclockwise by default; a negative value draws the arc in the clockwise direction. Note: This is only used when normal has been input.
negative (bool, optional) β
By default the arc spans the shortest angular sector point1 and point2.
By setting this to true, the longest angular sector is used instead (i.e. the negative coterminal angle to the shortest one). This is only used when normal has not been input
Examples
Quarter arc centered at the origin in the xy plane
>>> import pyvista >>> arc = pyvista.CircularArc([-1, 0, 0], [0, 1, 0], [0, 0, 0]) >>> pl = pyvista.Plotter() >>> _ = pl.add_mesh(arc, color='k', line_width=4) >>> _ = pl.show_bounds(location='all') >>> _ = pl.view_xy() >>> pl.show()
Quarter arc centered at the origin in the xz plane
>>> arc = pyvista.CircularArc([-1, 0, 0], [1, 0, 0], [0, 0, 0], normal=[0, 0, 1]) >>> arc.plot()
-
pyvista.
Pyramid
(points)ΒΆ Create a pyramid defined by 5 points.
- Parameters
points (np.ndarray or list) β Points of the pyramid. Points are ordered such that the first four points are the four counterclockwise points on the quadrilateral face, and the last point is the apex.
- Returns
pyramid
- Return type
Examples
>>> import pyvista >>> pointa = [1.0, 1.0, 1.0] >>> pointb = [-1.0, 1.0, 1.0] >>> pointc = [-1.0, -1.0, 1.0] >>> pointd = [1.0, -1.0, 1.0] >>> pointe = [0.0, 0.0, 0.0] >>> pyramid = pyvista.Pyramid([pointa, pointb, pointc, pointd, pointe]) >>> pyramid.plot()