Home > bobstuff > rot.m

rot

PURPOSE ^

ROT rotates a vector counterclockwise,

SYNOPSIS ^

function [xr,yr]=rot(x,y,theta,ya)

DESCRIPTION ^

 ROT rotates a vector counterclockwise, 

 [xr,yr]=ROT(x,y,theta,ya) rotates a vector counterclockwise 
 theta degrees OR rotates the coordinate system clockwise 
 theta degrees. Example: rot(1,0,90) returns (0,1).            

 If 4 arguments, then it uses xa and ya as orientation
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 ver. 1: 11/17/96 (RG)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001   function [xr,yr]=rot(x,y,theta,ya)
0002 
0003 % ROT rotates a vector counterclockwise,
0004 %
0005 % [xr,yr]=ROT(x,y,theta,ya) rotates a vector counterclockwise
0006 % theta degrees OR rotates the coordinate system clockwise
0007 % theta degrees. Example: rot(1,0,90) returns (0,1).
0008 %
0009 % If 4 arguments, then it uses xa and ya as orientation
0010 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0011 % ver. 1: 11/17/96 (RG)
0012 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0013 
0014 if nargin==4
0015 theta=-atan2(ya,theta)*180/pi;
0016 end
0017 
0018 costheta=cos(theta/180*pi);
0019 sintheta=sin(theta/180*pi);
0020 
0021 if length(theta)==1
0022     xr=x*costheta-y*sintheta;
0023     yr=x*sintheta+y*costheta;
0024 else
0025     xr=x.*costheta-y.*sintheta;
0026     yr=x.*sintheta+y.*costheta;
0027 end

Generated on Thu 01-Dec-2005 07:46:03 by m2html © 2003