I am given N
plane equations in the ax+by+cz+d=0
form, meaning we have their normals (a, b, c
) and distances from the origin (d
). In general, the planes are similar, so the coefficients do not differ very much. I do not have any points on the given planes, but I guess they can be sampled.
I need to find an equation of the plane which is closest to them all, i.e represents the cluster of the planes in the best way. To put it differently, I need to merge all the planes into one.
I've tried taking average of all plane coefficients, which produces a good result of the normal, but the last coefficient (d
) seems wrong, the resulting plane has a small offset from the cluster.
Here is the code that averages plane equations. It uses the Eigen library:
Eigen::Vector4d merged_plane(0,0,0,0);
// planes are normalized
for (size_t i = 0; i < planes.rows(); ++i) {
merged_plane += planes(i);
}
merged_plane /= planes.rows();
// Normalize
merged_plane /= merged_plane.head<3>().norm();
sqrt(a*a + b*b + c*c)
,d
is not the distance of the plane from the origin. Are the equations normalized? By "the planes are similar" do you mean that all the normalized equations, each coefficient includingd
is close to the same coefficient in all the other equations? By "closest" do you have a particular metric in mind or would any "close" plane suffice? Could you give us your sample data and code that averages the coefficients but gives an offset from the cluster? – Rory Daultond
represent the distance from the origin the normal vector(a,b,c)
must be normalized to length 1. Maybe it suffices to normalize the average normal vector (which will have a length < 1) again to length 1. – coproc