# microstructpy.geometry.Sphere¶

class microstructpy.geometry.Sphere(**kwargs)[source]

A 3D sphere.

This class represents a three-dimensional circle. It is defined by a center point and size parameter, which can be either radius or diameter.

Without input parameters, this defaults to a unit sphere centered at the origin.

Parameters: r (float) – (optional) The radius of the sphere. Defaults to 1. radius (float) – (optional) Same as r. d (float) – (optional) Alias for 2*r. diameter (float) – (optional) Alias for 2*r. size (float) – (optional) Alias for 2*r. center (list, float, numpy.ndarray) – (optional) The coordinates of the center. Defaults to [0, 0, 0]. position (list, float, numpy.ndarray) – (optional) Alias for center.
approximate()

Approximate the n-sphere with itself

Other geometries can be approximated by a set of circles or spheres. For the n-sphere, this approximation is exact.

Returns: A list containing [(x, y, z, …, r)] list
classmethod best_fit(points)

Find n-sphere of best fit for set of points.

This function takes a list of points and computes an n-sphere of best fit, in an algebraic sense. This method was developed using the a published writeup, which was extended from 2D to ND. [1]

Parameters: points (list, numpy.ndarray) – List of points to fit. An instance of the class that fits the points. NSphere
 [1] Circle fitting writup by Randy Bullock, https://dtcenter.org/met/users/docs/write_ups/circle_fit.pdf
plot(**kwargs)[source]

Plot the sphere.

This function uses the mpl_toolkits.mplot3d.Axes3D.plot_surface() method to add the sphere to the current axes. The keyword arguments are passed through to plot_surface.

Parameters: **kwargs (dict) – Keyword arguments for plot_surface.
reflect(points)

Reflect points across surface.

This function reflects a point or set of points across the surface of the n-sphere. Points at the center of the n-sphere are not reflected.

Parameters: points (list or numpy.ndarray) – Points to reflect. Reflected points. numpy.ndarray
classmethod volume_expectation(**kwargs)[source]

Expected value of volume.

This function computes the expected value for the volume of a sphere. The keyword arguments are identical to the Sphere function. The values for these keywords can be either constants or scipy.stats distributions.

The expected value is computed by the following formula:

$\begin{split}\mathbb{E}[V] &= \mathbb{E}[\frac{4}{3}\pi R^3] \\ &= \frac{4}{3}\pi \mathbb{E}[R^3] \\ &= \frac{4}{3}\pi (\mu_R^3 + 3 \mu_R \sigma_R^2 + \gamma_{1, R} \sigma_R^3)\end{split}$
Parameters: **kwargs – Keyword arguments, see microstructpy.geometry.Sphere. Expected value of the volume of the sphere. float
within(points)

Test if points are within n-sphere.

This function tests whether a point or set of points are within the n-sphere. For the set of points, a list of booleans is returned to indicate which points are within the n-sphere.

Parameters: points (list or numpy.ndarray) – Point or list of points. Set to True for points in geometry. bool or numpy.ndarray
bound_max

maximum bounding n-sphere

Type: tuple
bound_min

minimum interior n-sphere

Type: tuple
d

diameter of n-sphere.

Type: float
diameter

diameter of n-sphere.

Type: float
limits

list of (lower, upper) bounds for the bounding box

Type: list
n_dim

number of dimensions, 3

Type: int
position

position of n-sphere.

Type: list
radius

Type: float
sample_limits

list of (lower, upper) bounds for the sampling region

Type: list
size

size (diameter) of n-sphere.

Type: float
volume

volume of sphere

Type: float