skspatial.objects.Sphere.best_fit

classmethod Sphere.best_fit(points: Union[ndarray, Sequence]) Sphere[source]

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

Parameters:
pointsarray_like

Input 3D points.

Returns:
Sphere

The sphere of best fit.

Raises:
ValueError

If the points are not 3D. If there are fewer than four points. If the points lie in a plane.

Examples

>>> import numpy as np
>>> from skspatial.objects import Sphere
>>> points = [[1, 0, 1], [0, 1, 1], [1, 2, 1], [1, 1, 2]]
>>> sphere = Sphere.best_fit(points)
>>> sphere.point
Point([1., 1., 1.])
>>> np.round(sphere.radius, 2)
1.0