Code covered by the BSD License  

Highlights from
Defining Cartesian Reference Frames based on Point Positions

image thumbnail
from Defining Cartesian Reference Frames based on Point Positions by Paolo de Leva
Versatile algorithm defining Cartesian reference frames based on the positions of at least 3 points

testFRAME
function testFRAME
% TESTFRAME  Testing function FRAME
%    Example:
%    To perform a series of tests of function FRAME, use
%    TESTFRAME (without arguments)

alph =  pi/5;
bet  = -pi*0.66;
gam  =  pi*1.76;
R = Rx(eye(3),alph) * Ry(eye(3),bet) * Rz(eye(3),gam);
x = R(:,1);
y = R(:,2);
z = R(:,3);
check(R, x,y,z);

R = R(:,:,ones(1,20));
x = x(:,  ones(1,20));
y = y(:,  ones(1,20));
z = z(:,  ones(1,20));
check(R, x,y,z);

clear R2 x2 y2 z2;
R2 = permute(R, [3,1,2]);
x2 = x';
y2 = y';
z2 = z';
check(R2, x2,y2,z2);

clear R2 x2 y2 z2;
R2 = permute(R, [4,3,1,2]);
x2(1,:,:) = x';
y2(1,:,:) = y';
z2(1,:,:) = z';
check(R2, x2,y2,z2);


% -------------------------------------------------------------------------
function check(R, x,y,z)

x=x*33.3;
y=y*29.3;
z=z*40.567;

R1 = frame(x,y,'z', x,  'x');
R2 = frame(x,y,'z', z+x,'x');
R3 = frame(x,y,'z', y,  'y');
R4 = frame(x,y,'z', z+y,'y');

R5 = frame(y,z,'x', x+y,'y');
R6 = frame(y,z,'x', x+z,'z');

R7 = frame(z,x,'y', y+z,'z');
R8 = frame(z,x,'y', y+x,'x');

factor = 5;
if any( abs( R(:)-R1(:) ) > factor*eps ) || ...
   any( abs( R(:)-R2(:) ) > factor*eps ) || ...     
   any( abs( R(:)-R3(:) ) > factor*eps ) || ...     
   any( abs( R(:)-R4(:) ) > factor*eps ) || ...     
   any( abs( R(:)-R5(:) ) > factor*eps ) || ...     
   any( abs( R(:)-R6(:) ) > factor*eps ) || ...     
   any( abs( R(:)-R7(:) ) > factor*eps ) || ...     
   any( abs( R(:)-R8(:) ) > factor*eps )
   disp 'SOMETHING WRONG :-('
   pause
else
   disp ';-)'
   disp 'Only small differences found (rounding errors, smaller than'
   disp ([num2str(factor), ' times the machine precision EPS (2^-52)'])
   disp ';-)'
end
disp ' ';

Contact us at files@mathworks.com