[Matlab] LS(least squares)拟合3D平面

function [a,b,c,d]=get_LS_plane(data)
% a*x + b*y + c*z + d = 0
planeData=data;
% 协方差矩阵的SVD变换中,最小奇异值对应的奇异向量就是平面的方向
xyz0=mean(planeData,1);
centeredPlane=bsxfun(@minus,planeData,xyz0);
[~,~,V]=svd(centeredPlane);
a=V(1,3);
b=V(2,3);
c=V(3,3);
d=-dot([a b c],xyz0);

end

  

新裤子个人整理学习用
原文地址:https://www.cnblogs.com/LoveBuzz/p/9867130.html