fit_plane_to_points

fit_plane_to_points(points, return_meta=False)

Fit a plane to a set of points using the SVD algorithm.

Parameters
pointssequence

Size [N x 3] sequence of points to fit a plane through.

return_metabool, optional

If True, also returns the center and normal used to generate the plane.

Returns
pyvista.PolyData

Plane mesh.

numpy.ndarray

Plane center if return_meta=True.

numpy.ndarray

Plane normal if return_meta=True.

Examples

Fit a plane to a random point cloud.

>>> import pyvista
>>> import numpy as np
>>> cloud = np.random.random((10, 3))
>>> cloud[:, 2] *= 0.1
>>> plane, center, normal = pyvista.fit_plane_to_points(cloud, return_meta=True)

Plot the fitted plane.

>>> pl = pyvista.Plotter()
>>> _ = pl.add_mesh(plane, color='tan', style='wireframe', line_width=4)
>>> _ = pl.add_points(cloud, render_points_as_spheres=True, 
...                   color='r', point_size=30)
>>> pl.show()
../../../_images/pyvista-fit_plane_to_points-1_00_00.png