Mercurial > hg > ltpda
comparison m-toolbox/classes/@matrix/rotate.m @ 0:f0afece42f48
Import.
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Wed, 23 Nov 2011 19:22:13 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f0afece42f48 |
---|---|
1 % ROTATE applies rotation factor to matrix objects | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: ROTATE applies rotation factor to matrix objects | |
5 % | |
6 % CALL: B = rotate(A, pl) | |
7 % B1 = rotate(A1, pl) | |
8 % Bs = rotate(As, ang) | |
9 % | |
10 % INPUTS: Ai - matrix object(s) with AOs, size: [2 1] or [1 2] | |
11 % pl - parameter list | |
12 % ang - rotation angle as cdata AO or double | |
13 % | |
14 % Please notice that a positive rotation angle means rotating counterclockwise | |
15 % if we use the standard right-handed coordinate system, where x axis goes to | |
16 % the right and where y axis goes up. | |
17 % | |
18 % OUTPUTS: Bi - matrix object(s) with AOs, size: [2 1] or [1 2] with rotated data | |
19 % | |
20 % <a href="matlab:utils.helper.displayMethodInfo('matrix', 'rotate')">Parameters Description</a> | |
21 % | |
22 % VERSION: $Id: rotate.m,v 1.8 2011/04/08 08:56:31 hewitson Exp $ | |
23 % | |
24 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
25 | |
26 function varargout = rotate(varargin) | |
27 | |
28 % check if this is a call for parameters | |
29 if utils.helper.isinfocall(varargin{:}) | |
30 varargout{1} = getInfo(varargin{3}); | |
31 return | |
32 end | |
33 | |
34 import utils.const.* | |
35 utils.helper.msg(msg.PROC3, 'running %s/%s', mfilename('class'), mfilename); | |
36 | |
37 % collect input variable names | |
38 in_names = cell(size(varargin)); | |
39 for ii = 1:nargin,in_names{ii} = inputname(ii); end | |
40 | |
41 % collect all MATRIX, AOs and plists | |
42 [ms, matrix_invars, rest] = utils.helper.collect_objects(varargin(:), 'matrix', in_names); | |
43 [pli, invars, rest] = utils.helper.collect_objects(rest(:), 'plist', in_names); | |
44 | |
45 % make copies or handles to inputs | |
46 bs = copy(ms, nargout); | |
47 | |
48 % combine plists | |
49 pl = combine(pli, getDefaultPlist); | |
50 | |
51 % collect input histories | |
52 inhists = copy([ms.hist], true); | |
53 | |
54 % exctracts info about the rotation angle from the plist | |
55 ang = mfind(pl, 'ang', 'angle'); | |
56 | |
57 switch class(ang) | |
58 case 'double' | |
59 % look in rest | |
60 if ang == 0 && ~isempty(rest) | |
61 ang = rest{1}; | |
62 % store angle into the plist to add it to history | |
63 pl.pset('ang', ang); | |
64 end | |
65 case 'ao' | |
66 otherwise | |
67 error('### wrong container %s for the rotation angle. It can be a double or an ao', class(ang)) | |
68 end | |
69 | |
70 if isa(ang, 'ao') | |
71 % extract value | |
72 ang = ang.y; | |
73 end | |
74 | |
75 % check that ang is a number | |
76 if isempty(ang) || ~isnumeric(ang) || numel(ang) ~= 1 | |
77 error('### rotation angle must be scalar value'); | |
78 end | |
79 | |
80 % Loop over input MATRIX objects | |
81 for jj = 1 : numel(bs) | |
82 % deal with columns | |
83 if ~isequal(size(bs(jj).objs), [1 2]) && ~isequal(size(bs(jj).objs), [2 1]) | |
84 error('### rotate accepts only 2x1 or 1x2 matrices') | |
85 end | |
86 | |
87 % construct rotation matrix | |
88 m = [ cos(ang) -sin(ang) | |
89 sin(ang) cos(ang) ]; | |
90 | |
91 % arrange input values into a column vector | |
92 xy = [ transpose(bs(jj).objs(1).y); transpose(bs(jj).objs(2).y) ]; | |
93 | |
94 % apply the rotation matrix | |
95 xyr = m * xy; | |
96 | |
97 % set output values | |
98 bs(jj).objs(1).data.y = xyr(1,:); | |
99 bs(jj).objs(2).data.y = xyr(2,:); | |
100 | |
101 % set name | |
102 bs(jj).setName(sprintf('rotate(%s)', matrix_invars{jj})); | |
103 | |
104 % update history | |
105 bs(jj).addHistory(getInfo('None'), pl, matrix_invars, inhists); | |
106 | |
107 end | |
108 | |
109 % Set output | |
110 if nargout == numel(bs) | |
111 % List of outputs | |
112 for ii = 1:numel(bs) | |
113 varargout{ii} = bs(ii); | |
114 end | |
115 else | |
116 % Single output | |
117 varargout{1} = bs; | |
118 end | |
119 end | |
120 | |
121 %-------------------------------------------------------------------------- | |
122 % Get Info Object | |
123 %-------------------------------------------------------------------------- | |
124 function ii = getInfo(varargin) | |
125 if nargin == 1 && strcmpi(varargin{1}, 'None') | |
126 sets = {}; | |
127 pls = []; | |
128 else | |
129 sets = {'Default'}; | |
130 pls = getDefaultPlist; | |
131 end | |
132 % build info object | |
133 ii = minfo(mfilename, 'matrix', 'ltpda', utils.const.categories.op, '$Id: rotate.m,v 1.8 2011/04/08 08:56:31 hewitson Exp $', sets, pls); | |
134 ii.setArgsmin(1); | |
135 ii.setOutmin(1); | |
136 end | |
137 | |
138 %-------------------------------------------------------------------------- | |
139 % Get Default Plist | |
140 %-------------------------------------------------------------------------- | |
141 function plout = getDefaultPlist() | |
142 persistent pl; | |
143 if exist('pl', 'var')==0 || isempty(pl) | |
144 pl = buildplist(); | |
145 end | |
146 plout = pl; | |
147 end | |
148 | |
149 function pl = buildplist() | |
150 | |
151 pl = plist(); | |
152 p = param({'ang', 'The angle to rotate by. It can be a double or an AO.'}, paramValue.DOUBLE_VALUE(0)); | |
153 pl.append(p); | |
154 | |
155 end |