-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathrot.m
More file actions
25 lines (22 loc) · 765 Bytes
/
rot.m
File metadata and controls
25 lines (22 loc) · 765 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
function [xr,yr]=rot(x,y,theta,ya)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [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)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
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