StructuredSphere#
- StructuredSphere(
- *,
- radius: float | VectorLike[float] = 0.5,
- center: VectorLike[float] = (0.0, 0.0, 0.0),
- direction: VectorLike[float] = (0.0, 0.0, 1.0),
- theta_resolution: int = 30,
- phi_resolution: int = 30,
- start_theta: float = 0.0,
- end_theta: float = 360.0,
- start_phi: float = 0.0,
- end_phi: float = 180.0,
Create a sphere as a
StructuredGrid.The grid is generated in spherical coordinates and has an
i-j-kordering wherei,j, andkcorrespond to the radial, polar (phi), and azimuthal (theta) directions, respectively. LikeCylinderStructured(), a singleradiusgenerates a 2D surface ofQUADcells whereas a sequence of radii generates a 3D volume ofHEXAHEDRONcells.PyVista uses a convention where
thetarepresents the azimuthal angle (similar to degrees longitude on the globe) andphirepresents the polar angle (similar to degrees latitude on the globe). In contrast to latitude on the globe, herephiis 0 degrees at the North Pole and 180 degrees at the South Pole.phi=0is on the positive z-axis by default.theta=0is on the positive x-axis by default.With a sequence of radii the tessellation matches
SolidSphere()at the same resolutions, cell for cell and by volume; only the storage differs. Every cell here is aHEXAHEDRON, collapsed to a wedge shape at the poles whereSolidSphere()usesWEDGEcells and no coincident points, and onlySolidSphere()can fill the center. Prefer this function for thei-j-kordering, which addresses the grid by radius,phiandthetadirectly.Note that the poles have degenerate cells with coincident points, and that a full 360-degree sweep of
thetahas a seam of duplicate points where the start and end angles meet. Both are required by the grid’s structure. UseSphere()withtessellation='phi_theta'for a 2D surface, orSolidSphere()for a 3D volume; neither has coincident points or degenerate cells.Added in version 0.49.
- Parameters:
- radius
float| sequence[float], default: 0.5 Sphere radius, which must be greater than zero. If a sequence, then describes the radial coordinates of the cells as a range of values, and generates a 3D grid with concentric layers of cells. The sequence must be sorted in strictly ascending order.
- centersequence[
float], default: (0.0, 0.0, 0.0) Center coordinate vector in
[x, y, z].- directionsequence[
float], default: (0.0, 0.0, 1.0) Direction coordinate vector in
[x, y, z]pointing fromcenterto the sphere’s North Pole at zero degreesphi.- theta_resolution
int, default: 30 Set the number of points in the azimuthal direction (ranging from
start_thetatoend_theta).Note
The
kdimension of the structured grid is always one more than this value. For a full 360-degree sweep the extra point is the duplicate closing the seam.- phi_resolution
int, default: 30 Set the number of points in the polar direction (ranging from
start_phitoend_phi).- start_theta
float, default: 0.0 Starting azimuthal angle in degrees.
- end_theta
float, default: 360.0 Ending azimuthal angle in degrees. Must be greater than
start_thetaand within 360 degrees of it.- start_phi
float, default: 0.0 Starting polar angle in degrees
[0, 180].- end_phi
float, default: 180.0 Ending polar angle in degrees
[0, 180]. Must be greater thanstart_phi.
- radius
- Returns:
pyvista.StructuredGridStructured sphere.
Examples#
Download Python source code | Download Jupyter notebook
Create a sphere as a structured surface using default parameters.
>>> import numpy as np
>>> import pyvista as pv
>>> sphere = pv.StructuredSphere()
>>> sphere.plot(show_edges=True)
The dimensions follow the i-j-k ordering: one entry per radius, then
phi_resolution, then theta_resolution plus one.
>>> pv.StructuredSphere(theta_resolution=20, phi_resolution=10).dimensions
(1, 10, 21)
Swapping the two resolutions swaps the last two dimensions, and the extra point stays with theta.
>>> pv.StructuredSphere(theta_resolution=10, phi_resolution=20).dimensions
(1, 20, 11)
Use a sequence of radii to set the first dimension and generate a 3D grid with concentric layers of cells. This is useful for modeling volumetric data such as an atmosphere.
>>> pv.StructuredSphere(
... radius=[1.0, 1.5, 2.0], theta_resolution=20, phi_resolution=10
... ).dimensions
(3, 10, 21)
Show the layers by clipping the grid in half.
>>> sphere = pv.StructuredSphere(radius=np.linspace(1, 2, 5))
>>> sphere.clip(normal='x').plot(show_edges=True)
Create a partial sphere by restricting the angular ranges.
>>> sphere = pv.StructuredSphere(
... start_theta=90, end_theta=270, start_phi=30, end_phi=150
... )
>>> sphere.plot(show_edges=True)
Use the i-j-k ordering to work with the grid by index. Since i is the
radial axis, an array shaped like
dimensions assigns a value per layer.
>>> sphere = pv.StructuredSphere(radius=np.linspace(1, 2, 5))
>>> layer = np.zeros(sphere.dimensions)
>>> layer[:] = np.arange(5).reshape(5, 1, 1)
>>> sphere['layer'] = layer.ravel(order='F')
>>> sphere.clip(normal='y').plot(scalars='layer', show_edges=True)
The same indexing selects part of the grid, here the outermost layer of points.
>>> outer = sphere.extract_subset([4, 4, 0, 29, 0, 30])
>>> outer.dimensions
(1, 30, 31)
See Also#
pyvista.SphereSphere that describes outer 2D surface.
pyvista.SolidSphereSphere that fills 3D space.
pyvista.SolidSphereGenericSolid sphere using flexible sampling.
pyvista.CylinderStructuredCylinder as a
StructuredGrid.
Used In#
Gallery Examples