Solve plane equation with 3 points and additional condition
Ältere Kommentare anzeigen
I am quite new to matlab and only now some of the basic features, so every new problem cause trouble for me.
Given:
p1 = [x1 y1 z1]
p2 = [x2 y2 z2]
p3 = [x3 y3 z3]
Wanted: I need to find a plane
p = [a b c d]'
which satisfies the followind conditions
% should d = 1 or d = 0?
[p1 1; p2 1; p3 1] * [a b c d]' = 0
But solving this leads to the zero vector and also it does not incorporate the second condition.
Akzeptierte Antwort
Weitere Antworten (1)
You can use my planefit() utility
[abc,d]=planefit([p1;p2;p3].');
d=-d;
function varargout=planefit(xyz)
%Fit 3D plane to given (x,y,z) data
%
% [a,b,c,d] = planefit(xyz)
% [abc,d] = planefit(xyz)
% hcoeff = planefit(xyz)
%
%IN:
%
% xyz: 3xN input array with coordinates organized in columns
% [x1,x2,x3...;y1,y2,y3,...;z1,z2,z3,...]
%
%OUT:
%
% [a,b,c,d] : Coefficients of fitted plane equation a*x+b*y+c*z=d
% [abc,d] : Coefficients in 2-argument form where abc=[a,b,c]
% hcoeff : Homogeneous coefficient vector hcoeff=[a,b,c,-d]
if size(xyz,1)~=3
error 'Input xyz matrix must be 3xN'
end
xyz=xyz.';
mu=mean(xyz,1);
[~,~,V]=svd(xyz-mu,0);
normal=V(:,end).';
d=normal*mu';
switch nargout
case {0,1}
varargout={[normal,-d]};
case 2
varargout={ normal, d};
case 4
varargout=[num2cell(normal),{d}];
otherwise
error 'Must be 1,2, or 4 output args'
end
end
Kategorien
Mehr zu Interpolation finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

