Easier Pythonic interface to VTK for 3D scientific data visualization and mesh analysis
—
PyVista provides comprehensive functions for creating basic geometric shapes and parametric surfaces, essential for building 3D scenes and geometric modeling.
Creates spherical meshes with customizable resolution and parameters.
def Sphere(radius=0.5, center=(0.0, 0.0, 0.0), direction=(0.0, 0.0, 1.0),
theta_resolution=30, phi_resolution=30, start_theta=0.0, end_theta=360.0,
start_phi=0.0, end_phi=180.0) -> PolyData:
"""
Create a sphere mesh.
Parameters:
radius (float): Sphere radius
center (tuple): Center point coordinates (x, y, z)
direction (tuple): Direction vector for sphere orientation
theta_resolution (int): Number of points in longitude direction
phi_resolution (int): Number of points in latitude direction
start_theta (float): Starting longitude angle in degrees
end_theta (float): Ending longitude angle in degrees
start_phi (float): Starting latitude angle in degrees
end_phi (float): Ending latitude angle in degrees
Returns:
PolyData: Spherical mesh
"""Creates cubic and rectangular box meshes.
def Cube(x_length=1.0, y_length=1.0, z_length=1.0, center=(0.0, 0.0, 0.0)) -> PolyData:
"""
Create a cube mesh.
Parameters:
x_length (float): Length in x-direction
y_length (float): Length in y-direction
z_length (float): Length in z-direction
center (tuple): Center point coordinates
Returns:
PolyData: Cubic mesh
"""
def Box(bounds=(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0), level=0, quads=True) -> PolyData:
"""
Create a box mesh from bounds.
Parameters:
bounds (tuple): Bounds (xmin, xmax, ymin, ymax, zmin, zmax)
level (int): Subdivision level
quads (bool): Generate quadrilaterals instead of triangles
Returns:
PolyData: Box mesh
"""Creates cylindrical meshes with customizable caps and resolution.
def 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) -> PolyData:
"""
Create a cylinder mesh.
Parameters:
center (tuple): Center point of cylinder
direction (tuple): Direction vector for cylinder axis
radius (float): Cylinder radius
height (float): Cylinder height
resolution (int): Number of points around circumference
capping (bool): Cap the ends of cylinder
Returns:
PolyData: Cylindrical mesh
"""Creates conical meshes with customizable parameters.
def Cone(center=(0.0, 0.0, 0.0), direction=(1.0, 0.0, 0.0), height=1.0,
radius=0.5, capping=True, angle=None, resolution=6) -> PolyData:
"""
Create a cone mesh.
Parameters:
center (tuple): Center point of cone base
direction (tuple): Direction vector from base to apex
height (float): Cone height
radius (float): Base radius
capping (bool): Cap the base
angle (float): Cone angle in degrees (alternative to radius)
resolution (int): Number of points around base
Returns:
PolyData: Conical mesh
"""Creates planar surfaces with customizable resolution.
def Plane(center=(0.0, 0.0, 0.0), direction=(0.0, 0.0, 1.0), i_size=1, j_size=1,
i_resolution=10, j_resolution=10) -> PolyData:
"""
Create a plane mesh.
Parameters:
center (tuple): Center point of plane
direction (tuple): Normal vector of plane
i_size (float): Size in first direction
j_size (float): Size in second direction
i_resolution (int): Number of points in first direction
j_resolution (int): Number of points in second direction
Returns:
PolyData: Planar mesh
"""Creates circular and disc-shaped meshes.
def Circle(radius=0.5, resolution=100) -> PolyData:
"""
Create a circular mesh (line loop).
Parameters:
radius (float): Circle radius
resolution (int): Number of points around circumference
Returns:
PolyData: Circular line mesh
"""
def Disc(center=(0.0, 0.0, 0.0), inner=0.25, outer=0.5, normal=(0.0, 0.0, 1.0),
r_res=1, c_res=6) -> PolyData:
"""
Create a disc (annulus) mesh.
Parameters:
center (tuple): Center point
inner (float): Inner radius
outer (float): Outer radius
normal (tuple): Normal vector
r_res (int): Radial resolution
c_res (int): Circumferential resolution
Returns:
PolyData: Disc mesh
"""Creates rectangular and arbitrary polygonal shapes.
def Rectangle(dimensions=(1.0, 1.0), center=(0.0, 0.0, 0.0)) -> PolyData:
"""
Create a rectangular mesh.
Parameters:
dimensions (tuple): Width and height
center (tuple): Center point coordinates
Returns:
PolyData: Rectangular mesh
"""
def Polygon(center=(0.0, 0.0, 0.0), radius=1.0, normal=(0.0, 0.0, 1.0),
n_sides=6) -> PolyData:
"""
Create a regular polygon mesh.
Parameters:
center (tuple): Center point
radius (float): Distance from center to vertices
normal (tuple): Normal vector
n_sides (int): Number of sides
Returns:
PolyData: Polygonal mesh
"""
def Triangle(points=None) -> PolyData:
"""
Create a triangle from three points.
Parameters:
points (array-like): Three points defining triangle vertices
Returns:
PolyData: Triangular mesh
"""
def Quadrilateral(points=None) -> PolyData:
"""
Create a quadrilateral from four points.
Parameters:
points (array-like): Four points defining quadrilateral vertices
Returns:
PolyData: Quadrilateral mesh
"""
def Ellipse(semi_major_axis=0.5, semi_minor_axis=0.2, center=(0.0, 0.0, 0.0),
normal=(0.0, 0.0, 1.0), resolution=100) -> PolyData:
"""
Create an ellipse curve.
Parameters:
semi_major_axis (float): Length of semi-major axis
semi_minor_axis (float): Length of semi-minor axis
center (tuple): Center point of ellipse
normal (tuple): Normal vector of ellipse plane
resolution (int): Number of points around ellipse
Returns:
PolyData: Elliptical curve
"""
def Pyramid(points=None) -> PolyData:
"""
Create a pyramid from base points and apex.
Parameters:
points (array-like): Points defining pyramid base and apex
Returns:
PolyData: Pyramid mesh
"""Creates line segments and polylines.
def Line(pointa=(-0.5, 0.0, 0.0), pointb=(0.5, 0.0, 0.0), resolution=1) -> PolyData:
"""
Create a line mesh between two points.
Parameters:
pointa (tuple): Starting point coordinates
pointb (tuple): Ending point coordinates
resolution (int): Number of intermediate points
Returns:
PolyData: Line mesh
"""
def MultipleLines(points) -> PolyData:
"""
Create multiple line segments from point arrays.
Parameters:
points (array-like): Points defining line segments
Returns:
PolyData: Multi-line mesh
"""
def CircularArc(pointa=(-1.0, 0.0, 0.0), pointb=(0.0, 1.0, 0.0),
center=(0.0, 0.0, 0.0), resolution=20, negative=False) -> PolyData:
"""
Create a circular arc between two points.
Parameters:
pointa (tuple): Starting point coordinates
pointb (tuple): Ending point coordinates
center (tuple): Arc center point
resolution (int): Number of points along arc
negative (bool): Use negative arc direction
Returns:
PolyData: Circular arc mesh
"""
def CircularArcFromNormal(center=(0.0, 0.0, 0.0), resolution=20,
normal=(0.0, 0.0, 1.0), polar=(1.0, 0.0, 0.0),
angle=90.0) -> PolyData:
"""
Create a circular arc from normal and polar vectors.
Parameters:
center (tuple): Arc center point
resolution (int): Number of points along arc
normal (tuple): Normal vector to arc plane
polar (tuple): Starting direction vector
angle (float): Arc angle in degrees
Returns:
PolyData: Circular arc mesh
"""Creates arrow-shaped meshes for vector visualization.
def 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) -> PolyData:
"""
Create an arrow mesh.
Parameters:
start (tuple): Starting point of arrow
direction (tuple): Direction vector
tip_length (float): Length of arrow tip
tip_radius (float): Radius of arrow tip
tip_resolution (int): Resolution of arrow tip
shaft_radius (float): Radius of arrow shaft
shaft_resolution (int): Resolution of arrow shaft
scale (float): Overall scale factor
Returns:
PolyData: Arrow mesh
"""Creates tubular meshes along paths.
def Tube(pointa=(-0.5, 0.0, 0.0), pointb=(0.5, 0.0, 0.0), resolution=1,
radius=1.0, n_sides=3) -> PolyData:
"""
Create a tube mesh along a path.
Parameters:
pointa (tuple): Starting point
pointb (tuple): Ending point
resolution (int): Number of segments along path
radius (float): Tube radius
n_sides (int): Number of sides around circumference
Returns:
PolyData: Tubular mesh
"""Creates mathematical superquadric surfaces.
def Superquadric(center=(0.0, 0.0, 0.0), scale=(1.0, 1.0, 1.0), size=0.5,
theta_roundness=1.0, phi_roundness=1.0, theta_resolution=16,
phi_resolution=16, toroidal=False, thickness=1/3) -> PolyData:
"""
Create a superquadric mesh.
Parameters:
center (tuple): Center point
scale (tuple): Scaling factors for each axis
size (float): Overall size
theta_roundness (float): Roundness in theta direction
phi_roundness (float): Roundness in phi direction
theta_resolution (int): Resolution in theta direction
phi_resolution (int): Resolution in phi direction
toroidal (bool): Create toroidal superquadric
thickness (float): Thickness for toroidal shapes
Returns:
PolyData: Superquadric mesh
"""Creates 3D text meshes.
def Text3D(string, depth=0.5) -> PolyData:
"""
Create 3D text mesh.
Parameters:
string (str): Text string to render
depth (float): Extrusion depth
Returns:
PolyData: 3D text mesh
"""
def Capsule(center=(0.0, 0.0, 0.0), direction=(1.0, 0.0, 0.0), radius=0.5,
cylinder_length=1.0, resolution=30) -> PolyData:
"""
Create a capsule mesh.
Parameters:
center (tuple): Center point of capsule
direction (tuple): Direction vector along capsule axis
radius (float): Capsule radius
cylinder_length (float): Length of cylindrical section
resolution (int): Number of points around circumference
Returns:
PolyData: Capsule mesh
"""
def CylinderStructured(center=(0.0, 0.0, 0.0), direction=(1.0, 0.0, 0.0),
radius=0.5, height=1.0, theta_resolution=32,
z_resolution=10) -> StructuredGrid:
"""
Create a structured cylinder grid.
Parameters:
center (tuple): Center point of cylinder
direction (tuple): Direction vector for cylinder axis
radius (float): Cylinder radius
height (float): Cylinder height
theta_resolution (int): Circumferential resolution
z_resolution (int): Axial resolution
Returns:
StructuredGrid: Structured cylindrical grid
"""
def Wavelet(extent=(-10, 10, -10, 10, -10, 10), center=(0.0, 0.0, 0.0),
maximum=255.0, x_freq=60.0, y_freq=30.0, z_freq=40.0,
x_mag=10.0, y_mag=18.0, z_mag=5.0, std=0.5,
subsample_rate=1) -> ImageData:
"""
Create a wavelet dataset.
Parameters:
extent (tuple): Data extent (xmin, xmax, ymin, ymax, zmin, zmax)
center (tuple): Center point
maximum (float): Maximum value
x_freq (float): X frequency
y_freq (float): Y frequency
z_freq (float): Z frequency
x_mag (float): X magnitude
y_mag (float): Y magnitude
z_mag (float): Z magnitude
std (float): Standard deviation
subsample_rate (int): Subsample rate
Returns:
ImageData: Wavelet dataset
"""
def SolidSphere(radius=0.5, center=(0.0, 0.0, 0.0), u_resolution=6,
v_resolution=4, w_resolution=4, start_u=0.0, end_u=6.28318530718,
start_v=0.0, end_v=3.14159265359, start_w=0.0,
end_w=6.28318530718) -> ImageData:
"""
Create a solid sphere volume.
Parameters:
radius (float): Sphere radius
center (tuple): Center coordinates
u_resolution (int): U direction resolution
v_resolution (int): V direction resolution
w_resolution (int): W direction resolution
start_u (float): Start U parameter
end_u (float): End U parameter
start_v (float): Start V parameter
end_v (float): End V parameter
start_w (float): Start W parameter
end_w (float): End W parameter
Returns:
ImageData: Solid sphere volume
"""Regular polyhedra with equal faces and angles.
def Tetrahedron(radius=1.0, center=(0.0, 0.0, 0.0)) -> PolyData:
"""Create a tetrahedron (4 triangular faces)."""
def Octahedron(radius=1.0, center=(0.0, 0.0, 0.0)) -> PolyData:
"""Create an octahedron (8 triangular faces)."""
def Dodecahedron(radius=1.0, center=(0.0, 0.0, 0.0)) -> PolyData:
"""Create a dodecahedron (12 pentagonal faces)."""
def Icosahedron(radius=1.0, center=(0.0, 0.0, 0.0)) -> PolyData:
"""Create an icosahedron (20 triangular faces)."""
def Icosphere(radius=1.0, center=(0.0, 0.0, 0.0), nsub=1) -> PolyData:
"""
Create an icosphere by subdividing an icosahedron.
Parameters:
radius (float): Sphere radius
center (tuple): Center coordinates
nsub (int): Number of subdivision levels
Returns:
PolyData: Icosphere mesh
"""
def PlatonicSolid(kind='tetrahedron', radius=1.0, center=(0.0, 0.0, 0.0)) -> PolyData:
"""
Create a platonic solid.
Parameters:
kind (str): Type of solid ('tetrahedron', 'cube', 'octahedron', 'icosahedron', 'dodecahedron')
radius (float): Circumscribed radius
center (tuple): Center coordinates
Returns:
PolyData: Platonic solid mesh
"""Mathematical parametric surfaces for advanced geometric modeling.
def ParametricTorus(ringradius=1.0, crosssectionradius=0.2, u_res=50,
v_res=50, u_min=0.0, u_max=6.283185307179586,
v_min=0.0, v_max=6.283185307179586) -> PolyData:
"""Create a parametric torus surface."""
def ParametricEllipsoid(xradius=1.0, yradius=1.0, zradius=1.0, u_res=50,
v_res=50, u_min=0.0, u_max=6.283185307179586,
v_min=0.0, v_max=3.141592653589793) -> PolyData:
"""Create a parametric ellipsoid surface."""
def ParametricKlein(u_res=50, v_res=50, u_min=0.0, u_max=6.283185307179586,
v_min=0.0, v_max=6.283185307179586) -> PolyData:
"""Create a Klein bottle surface."""
def ParametricBoy(zscale=1.0, u_res=50, v_res=50, u_min=0.0,
u_max=3.141592653589793, v_min=0.0,
v_max=3.141592653589793) -> PolyData:
"""Create a Boy's surface."""
def ParametricBohemianDome(u_res=50, v_res=50) -> PolyData:
"""Create a Bohemian dome surface."""
def ParametricBour(u_res=50, v_res=50) -> PolyData:
"""Create a Bour surface."""
def ParametricCatalanMinimal(u_res=50, v_res=50) -> PolyData:
"""Create a Catalan minimal surface."""
def ParametricConicSpiral(u_res=50, v_res=50) -> PolyData:
"""Create a conic spiral surface."""
def ParametricCrossCap(u_res=50, v_res=50) -> PolyData:
"""Create a cross cap surface."""
def ParametricDini(a=1.0, b=0.2, u_res=50, v_res=50) -> PolyData:
"""Create a Dini surface."""
def ParametricEnneper(u_res=50, v_res=50) -> PolyData:
"""Create an Enneper surface."""
def ParametricFigure8Klein(radius=1.0, u_res=50, v_res=50) -> PolyData:
"""Create a Figure-8 Klein bottle."""
def ParametricHenneberg(u_res=50, v_res=50) -> PolyData:
"""Create a Henneberg surface."""
def ParametricKuen(deltav0=0.001, u_res=50, v_res=50) -> PolyData:
"""Create a Kuen surface."""
def ParametricMobius(radius=1.0, u_res=50, v_res=50) -> PolyData:
"""Create a Mobius strip."""
def ParametricPluckerConoid(n=2, u_res=50, v_res=50) -> PolyData:
"""Create a Plucker conoid."""
def ParametricPseudosphere(u_res=50, v_res=50) -> PolyData:
"""Create a pseudosphere."""
def ParametricRandomHills(u_res=50, v_res=50) -> PolyData:
"""Create a random hills surface."""
def ParametricRoman(radius=1.0, u_res=50, v_res=50) -> PolyData:
"""Create a Roman surface."""
def ParametricSuperEllipsoid(u_res=50, v_res=50) -> PolyData:
"""Create a super ellipsoid."""
def ParametricSuperToroid(u_res=50, v_res=50) -> PolyData:
"""Create a super toroid."""Curve generation and spline interpolation.
def Spline(points, n_points=None) -> PolyData:
"""
Create a spline through given points.
Parameters:
points (array-like): Control points for spline
n_points (int): Number of points in output spline
Returns:
PolyData: Spline curve
"""
def KochanekSpline(points, tension=0.0, bias=0.0, continuity=0.0,
n_points=None) -> PolyData:
"""
Create a Kochanek spline with tension, bias, and continuity control.
Parameters:
points (array-like): Control points
tension (float): Tension parameter
bias (float): Bias parameter
continuity (float): Continuity parameter
n_points (int): Number of output points
Returns:
PolyData: Kochanek spline curve
"""import pyvista as pv
# Create various geometric primitives
sphere = pv.Sphere(radius=1.0, theta_resolution=50, phi_resolution=50)
cube = pv.Cube(x_length=2.0, y_length=2.0, z_length=2.0)
cylinder = pv.Cylinder(radius=0.5, height=2.0, resolution=20)
cone = pv.Cone(radius=1.0, height=2.0, resolution=20)
# Plot multiple objects
plotter = pv.Plotter(shape=(2, 2))
plotter.subplot(0, 0)
plotter.add_mesh(sphere, color='red')
plotter.subplot(0, 1)
plotter.add_mesh(cube, color='blue')
plotter.subplot(1, 0)
plotter.add_mesh(cylinder, color='green')
plotter.subplot(1, 1)
plotter.add_mesh(cone, color='yellow')
plotter.show()import pyvista as pv
# Create various parametric surfaces
torus = pv.ParametricTorus(ringradius=2.0, crosssectionradius=0.5)
klein = pv.ParametricKlein()
boy = pv.ParametricBoy()
# Add some coloring based on coordinates
torus['x'] = torus.points[:, 0]
klein['y'] = klein.points[:, 1]
boy['z'] = boy.points[:, 2]
# Plot with different colormaps
plotter = pv.Plotter(shape=(1, 3))
plotter.subplot(0, 0)
plotter.add_mesh(torus, scalars='x', cmap='coolwarm')
plotter.subplot(0, 1)
plotter.add_mesh(klein, scalars='y', cmap='plasma')
plotter.subplot(0, 2)
plotter.add_mesh(boy, scalars='z', cmap='viridis')
plotter.show()Install with Tessl CLI
npx tessl i tessl/pypi-pyvista