skspatial.objects.Plane.best_fit

classmethod Plane.best_fit(points: Union[ndarray, Sequence], tol: Optional[float] = None, **kwargs) Plane[source]

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

Parameters:
pointsarray_like

Input 3D points.

tolfloat | None, optional

Keyword passed to Points.are_collinear() (default None).

kwargsdict, optional

Additional keywords passed to numpy.linalg.svd()

Returns:
Plane

The plane of best fit.

Raises:
ValueError

If the points are collinear or are not 3D.

References

Using SVD for some fitting problems Inge Söderkvist Algorithm 3.1 https://www.ltu.se/cms_fs/1.51590!/svd-fitting.pdf

Examples

>>> from skspatial.objects import Plane
>>> points = [[0, 0, 0], [1, 0, 0], [0, 1, 0], [0, 0, 1]]
>>> plane = Plane.best_fit(points)

The point on the plane is the centroid of the points.

>>> plane.point
Point([0.25, 0.25, 0.25])

The plane normal is a unit vector.

>>> plane.normal.round(3)
Vector([-0.577, -0.577, -0.577])
>>> points = [[0, 0, 0], [1, 0, 0], [0, 1, 0], [1, 1, 0]]
>>> Plane.best_fit(points)
Plane(point=Point([0.5, 0.5, 0. ]), normal=Vector([0., 0., 1.]))
>>> Plane.best_fit(points, full_matrices=False)
Plane(point=Point([0.5, 0.5, 0. ]), normal=Vector([0., 0., 1.]))