Skip to content

sphere

Sphere

Sphere utility class.

cartesian_to_polar classmethod

cartesian_to_polar(
    x: ndarray | float, y: ndarray | float, z: ndarray | float
) -> Tuple[ndarray | float, ndarray | float, ndarray | float]

Convert the directional coordinates from cartesian to polar coordinate system.

integrate classmethod

integrate(
    *coords: ndarray, csys: Literal["cartesian", "polar"] = "polar"
) -> float

Integrate the directional coordinates over the sphere.

meshgrid classmethod

meshgrid(
    n_theta: int = N_THETA_DEFAULT, n_phi: int = N_PHI_DEFAULT
) -> Tuple[ndarray, ndarray]

Create a meshgrid for the spherical coordinates.

normalize classmethod

normalize(theta: ndarray, phi: ndarray, radius: ndarray) -> ndarray

Normalize the directional coordinates over the sphere.

polar_to_cartesian classmethod

polar_to_cartesian(
    theta: ndarray | float, phi: ndarray | float, radius: ndarray | float
) -> Tuple[ndarray | float, ndarray | float, ndarray | float]

Convert the directional coordinates from polar to cartesian coordinate system.

sample_uniform classmethod

sample_uniform(
    n_sample: int = N_SAMPLE_DEFAULT,
    *,
    csys: Literal["cartesian", "polar"] = "polar"
) -> Tuple[ndarray, ndarray, ndarray]

Sample uniformly on the unit sphere [1] [2].

PARAMETER DESCRIPTION
n_sample

Number of samples, by default 1000.

TYPE: int DEFAULT: N_SAMPLE_DEFAULT

csys

Coordinate system to use, by default "polar"

TYPE: ('cartesian', 'polar') DEFAULT: "cartesian"

RETURNS DESCRIPTION
Tuple[ndarray, ndarray, ndarray]

Tuple of theta, phi, and r coordinates in polar coordinates or x, y, and z coordinates in cartesian coordinates.

References

.. [1] https://zhuanlan.zhihu.com/p/25988652 .. [2] https://pbr-book.org/3ed-2018/Monte_Carlo_Integration/2D_Sampling_with_Multidimensional_Transformations#UniformlySamplingaHemisphere

surface classmethod

surface(
    theta: ndarray,
    phi: ndarray,
    radius: ndarray,
    *,
    type: Literal["surface", "trisurf", "wireframe"] = "surface",
    positive_color: str | None = None,
    negative_color: str | None = None,
    ax: Union["Axes3D", None] = None,
    subplot_kwargs: dict | None = None,
    **kwargs
) -> Tuple["Figure", "Axes3D"]

Plot the spherical coordinates.

PARAMETER DESCRIPTION
theta

Meshgrid of theta, by default None.

TYPE: ndarray

phi

Meshgrid of phi, by default None.

TYPE: ndarray

radius

Meshgrid of radius, by default None.

TYPE: ndarray

type

Type of plot, by default "surface".

TYPE: Literal['surface', 'trisurf', 'wireframe'] DEFAULT: 'surface'

positive_color

Color for positive radius, by default None.

TYPE: str DEFAULT: None

negative_color

Color for negative radius, by default None.

TYPE: str DEFAULT: None

ax

Axes to plot on, by default None.

TYPE: Union['Axes3D', None] DEFAULT: None

subplot_kwargs

Keyword arguments passed to 🇵🇾func:~micromechanical.plotting.subplots for creating the subplot, by default None

TYPE: dict DEFAULT: None

kwargs

Keyword arguments passed to 🇵🇾func:~mpl_toolkits.mplot3d.axes3d.Axes3D.plot_surface.

DEFAULT: {}

RETURNS DESCRIPTION
Tuple[Figure, Axes3D]

Tuple of the figure and the axes.

trisurf classmethod

trisurf(
    theta: ndarray,
    phi: ndarray,
    radius: ndarray,
    *,
    ax: Union["Axes3D", None] = None,
    subplot_kwargs: dict | None = None,
    **kwargs
) -> Tuple["Figure", "Axes3D"]

wireframe classmethod

wireframe(
    theta: ndarray,
    phi: ndarray,
    radius: ndarray,
    *,
    ax: Union["Axes3D", None] = None,
    subplot_kwargs: dict | None = None,
    **kwargs
) -> Tuple["Figure", "Axes3D"]