Given a point cloud, what's the best way to find the closest plane that's fairly accurate but also fast enough?
I searched for nearest plane but couldn't find any related info.
I want to use this to snap them to this plane.
Given a point cloud, what's the best way to find the closest plane that's fairly accurate but also fast enough?
I searched for nearest plane but couldn't find any related info.
I want to use this to snap them to this plane.
Least squares regression would be my guess. It will give you the coefficients for the plane that minimizes the mean square error over all the points.
You aren't the first:
I think you could also do this using principal component analysis:
Compute the average of your points:
C = (0,0,0);
for each point Ri in your dataset,
{ C += Ri; }
C = C * 1.0 / npoints;
Compute the covariance matrix of your points:
A = zeros(3,3);
for each point Ri in your dataset,
{
D = Ri - C;
A += D*D'; // outer product
}
Compute the inverse of A, A_inv:
A_inv = inv(A)
Perform power iterations by repeatedly applying A_inv to a random initial vector:
N = random vector.
for i=1:20 (or so)
{
N = A_inv*N;
N = normalize(N);
}
The offset from the origin to your plane is k = dot(N,C). The equation that describes your plane is all points R such that k = dot(N,R).