skspatial.objects.Sphere

class skspatial.objects.Sphere(point: Union[numpy.ndarray, Sequence], radius: float)[source]

A sphere in 3D space.

The sphere is defined by a 3D point and a radius.

Parameters
point(3,) array_like

Center of the sphere.

radius{int, float}

Radius of the sphere.

Raises
ValueError

If the radius is not positive. If the point is not 3D.

Examples

>>> from skspatial.objects import Sphere
>>> sphere = Sphere([1, 2, 3], 5)
>>> sphere
Sphere(point=Point([1, 2, 3]), radius=5)
>>> sphere.dimension
3
>>> sphere.surface_area().round(2)
314.16
>>> Sphere([0, 0], 0)
Traceback (most recent call last):
...
ValueError: The radius must be positive.
>>> Sphere([0, 0, 0, 0], 1)
Traceback (most recent call last):
...
ValueError: The point must be 3D.
Attributes
point(3,) Point

Center of the sphere.

radius{int, float}

Radius of the sphere.

dimensionint

Dimension of the sphere.

Methods

best_fit(points)

Return the sphere of best fit for a set of 3D points.

intersect_line(line)

Intersect the sphere with a line.

plot_3d(ax_3d[, n_angles])

Plot the sphere in 3D.

surface_area()

Return the surface area of the sphere.

to_mesh([n_angles])

Return coordinate matrices for the 3D surface of the sphere.

to_points(**kwargs)

Return points on the surface of the object.

volume()

Return the volume of the sphere.