function  [XH,YH]=uvecsperp(D)
% Construct unit vectors XH and YH perp to D
% D is a 3 component real row vector (1-by-3)
% example:
%   [XH,YH]=uvecsperp([8,5,6])
% 
% Fabian Waleffe for Math 321, UW Feb 27, 2009

D=D/norm(D);       % make D unit vector
Z=[0,0,1];         % Zhat or reference system

XH=cross(Z,D);     % Zhat x Dhat is x' direction
if (norm(XH) <= 2^(-50))
    XH=[1,0,0];
else
XH=XH/norm(XH);    % unit vector in x' direction
end

YH=cross(D,XH);    % unit vector in y' direction

