function [xr,yr]=rot(x,y,theta,ya);
%function [xr,yr]=rot(x,y,theta,ya);
%      rotates a vector counterclockwise theta degrees
% OR   rotates the coord system clockwise theta degrees
%    rot(1,0,90) returns (0,1)
%   if 4 arguments then it uses xa and ya as orientation

if nargin==4
theta=-atan2(ya,theta)*180/pi;
end

costheta=cos(theta/180*pi);
sintheta=sin(theta/180*pi);

if length(theta)==1
    xr=x*costheta-y*sintheta;
    yr=x*sintheta+y*costheta;
else
    xr=x.*costheta-y.*sintheta;
    yr=x.*sintheta+y.*costheta;
end
