Doxygen Source Code Documentation
Plane_Equation.m
Go to the documentation of this file.00001 function [err,Eq] = Plane_Equation (Triplets, verbose)
00002 %
00003 % [err,Eq] = Plane_Equation (Triplets, [verbose])
00004 %
00005 %Purpose:
00006 % Determine the equation of the plane passing through three points
00007 %
00008 %
00009 %Input Parameters:
00010 % Triplets is an Nx1 vector of strucutres. Each structure defines a plane
00011 % .XYZ : is a 3x3 matrix containing the XYZ of each of the three points
00012 % Each row is a point. ie: XYZ = [0 0 0; 1 0 0; 1 1 1]; is for the
00013 % three points (0 0 0), (1 0 0) and (1 1 1).
00014 % If the three points are colinear, Eq = [0 0 0 0]
00015 %
00016 % verbose (0/1), default is 1
00017 %
00018 %Output Parameters:
00019 % err : 0 No Problem
00020 % : 1 Mucho Problems
00021 %
00022 % Eq is a Nx4 matrix containing the equation of the plane containing each
00023 % triplet in Triplets. The plane passing by triplet i is speicifed in
00024 % Eq(i,:) the plane would be Eq(i,1)x + Eq(i,2)y + Eq(i,3)z + Eq(i,4) = 0
00025 %
00026 %More Info :
00027 %
00028 % see also ShowPlane
00029 % try
00030 % Triplets(1).XYZ = [0 0 0; 1 0 0; 1 1 0];
00031 % Triplets(2).XYZ = [0 0 0; 1 0 0; 1 1 1];
00032 % Triplets(3).XYZ = [0 5 0; 1 5 0; 1 1 1];
00033 %
00034 % [err,Eq] = Plane_Equation (Triplets);
00035 % [err,PatchHandles] = ShowPlane (Eq); view(3)
00036 %
00037 % Author : Ziad Saad
00038 % Date : Thu Oct 22 16:09:56 CDT 1998
00039
00040
00041 %Define the function name for easy referencing
00042 FuncName = 'Plane_Equation';
00043
00044 %initailize return variables
00045 err = 1;
00046
00047 if (nargin == 1), verbose = 1; end
00048
00049 if (isrow(Triplets) == -1), err = ErrEval(FuncName,'Err_Triplets must be an Nx1 vector'); return; end
00050
00051 Triplets = Triplets(:);
00052 Nplanes = size(Triplets,1);
00053 Eq = zeros(Nplanes,4); %allocate
00054
00055 for (i=1:1:Nplanes),
00056 %Form the equation of the plane
00057 x1 = Triplets(i).XYZ(1,1); y1 = Triplets(i).XYZ(1,2); z1 = Triplets(i).XYZ(1,3);
00058 x2 = Triplets(i).XYZ(2,1); y2 = Triplets(i).XYZ(2,2); z2 = Triplets(i).XYZ(2,3);
00059 x3 = Triplets(i).XYZ(3,1); y3 = Triplets(i).XYZ(3,2); z3 = Triplets(i).XYZ(3,3);
00060 Eq(i,1) = y1.*(z2-z3) + y2.*(z3-z1) + y3.*(z1-z2);
00061 Eq(i,2) = z1.*(x2-x3) + z2.*(x3-x1) + z3.*(x1-x2);
00062 Eq(i,3) = x1.*(y2-y3) + x2.*(y3-y1) + x3.*(y1-y2);
00063 Eq(i,4) = -x1.*(y2.*z3 - y3.*z2) - x2.*(y3.*z1 - y1.*z3) - x3.*(y1.*z2 - y2.*z1);
00064
00065 if (verbose),
00066 if (~rem (i,200)),
00067 fprintf (1,'[%g/%g]\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b',i,Nplanes);
00068 end
00069
00070 end
00071 end
00072
00073 err = 0;
00074 return;
00075