pyvista.fit_plane_to_points#
- fit_plane_to_points(points, return_meta=False)[source]#
Fit a plane to a set of points using the SVD algorithm.
The plane is automatically sized and oriented to fit the extents of the points.
- Parameters:
- pointsarray_like[
float
] Size
[N x 3]
sequence of points to fit a plane through.- return_metabool, default:
False
If
True
, also returns the center and normal of the generated plane.
- pointsarray_like[
- 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 as pv >>> import numpy as np >>> >>> # Create point cloud >>> rng = np.random.default_rng(seed=0) >>> cloud = rng.random((10, 3)) >>> cloud[:, 2] *= 0.1 >>> >>> # Fit plane >>> plane, center, normal = pv.fit_plane_to_points( ... cloud, return_meta=True ... ) >>> >>> # Plot the fitted plane >>> pl = pv.Plotter() >>> _ = pl.add_mesh( ... plane, color='lightblue', style='wireframe', line_width=4 ... ) >>> _ = pl.add_points( ... cloud, ... render_points_as_spheres=True, ... color='r', ... point_size=30, ... ) >>> pl.show()
Fit a plane to a mesh.
>>> import pyvista as pv >>> from pyvista import examples >>> >>> # Create mesh >>> mesh = examples.download_shark() >>> >>> # Fit plane >>> plane = pv.fit_plane_to_points(mesh.points) >>> >>> # Plot the fitted plane >>> pl = pv.Plotter() >>> _ = pl.add_mesh( ... plane, show_edges=True, color='lightblue', opacity=0.25 ... ) >>> _ = pl.add_mesh(mesh, color='gray') >>> pl.camera_position = [ ... (-117, 76, 235), ... (1.69, -1.38, 0), ... (0.189, 0.957, -0.22), ... ] >>> pl.show()