function [n, e, d] = dircos(dir, incl, type)
% DIRCOR  Calculates direction cosines for planar or linear data.
%   [N, E, D] = DIRCOR(DIRECTION, INCLINATION, TYPE) calculates the direction 
%   cosines in a North, East, Down coordinate system for a line or plane given
%   its DIRECTION (trend or strike) and INCLINATION (plunge or dip).  Specify 
%   TYPE = 1 for a line and TYPE = 2 for a plane.
%
%   Angles should be in degrees, with plunge and dip given as positive numbers.
%

if type == 1
   n = cosd(incl).*cosd(dir);
   e = cosd(incl).*sind(dir);
   d = sind(incl);
elseif type == 2
   n = sind(dir).*sind(incl); % "sind" as opposed to "sin" works on degrees instead of radians
   e = -cosd(dir).*sind(incl);
   d = cosd(incl);
else
   error('Specify TYPE = 1 for lines or TYPE = 2 for planes.')
end