time | Calls | line |
---|
| | 1 | function m=makehgtform(varargin)
|
| | 2 | %MAKEHGTFORM Make a 4x4 transform matrix.
|
| | 3 | % M = MAKEHGTFORM Creates an identity transform.
|
| | 4 | %
|
| | 5 | % M = MAKEHGTFORM('translate',tx,ty,tz) Translate along X
|
| | 6 | % axis by tx, along Y axis by ty, and along Z axis by tz.
|
| | 7 | %
|
| | 8 | % M = MAKEHGTFORM('scale',s) Scale uniformly by s.
|
| | 9 | %
|
| | 10 | % M = MAKEHGTFORM('scale',[sx sy sz]) Scale along X axis by
|
| | 11 | % sx, along Y axis by sy, and along Z axis by sz.
|
| | 12 | %
|
| | 13 | % M = MAKEHGTFORM('xrotate',t) Rotate around X axis by t radians.
|
| | 14 | %
|
| | 15 | % M = MAKEHGTFORM('yrotate',t) Rotate around Y axis by t radians.
|
| | 16 | %
|
| | 17 | % M = MAKEHGTFORM('zrotate',t) Rotate around Z axis by t radians.
|
| | 18 | %
|
| | 19 | % M = MAKEHGTFORM('axisrotate',[ax ay az],t) Rotate around axis
|
| | 20 | % [ax ay az] by t radians.
|
| | 21 | %
|
| | 22 | % Multiple transforms can be concatenated.
|
| | 23 | %
|
| | 24 | % Example:
|
| | 25 | %
|
| | 26 | % m = makehgtform('xrotate',pi/2,'yrotate',pi/2);
|
| | 27 | %
|
| | 28 | % is the same as:
|
| | 29 | %
|
| | 30 | % m = makehgtform('xrotate',pi/2)*makehgtform('yrotate',pi/2);
|
| | 31 | %
|
| | 32 | % See also HGTRANSFORM.
|
| | 33 |
|
| | 34 | % Copyright 1984-2017 The MathWorks, Inc.
|
| | 35 |
|
| | 36 | import matlab.graphics.internal.*;
|
0.002 | 154 | 37 | m = eye(4);
|
< 0.001 | 154 | 38 | ai = 1;
|
< 0.001 | 154 | 39 | numArgs = length(varargin);
|
< 0.001 | 154 | 40 | while ai <= numArgs
|
0.002 | 308 | 41 | name = varargin{ai};
|
< 0.001 | 308 | 42 | ai = ai+1;
|
| | 43 |
|
0.001 | 308 | 44 | if strcmpi(name,'translate')
|
< 0.001 | 154 | 45 | narginchk(ai,inf);
|
| | 46 |
|
< 0.001 | 154 | 47 | if ~isnumeric(varargin{ai})
|
| | 48 | error(message('MATLAB:makehgtform:InvalidParamTranslateNumeric'));
|
< 0.001 | 154 | 49 | end
|
0.003 | 154 | 50 | x = double(varargin{ai});
|
< 0.001 | 154 | 51 | ai = ai+1;
|
| | 52 |
|
< 0.001 | 154 | 53 | if isscalar(x)
|
| | 54 | narginchk(ai+1,inf);
|
| | 55 |
|
| | 56 | if ~isnumeric(varargin{ai})
|
| | 57 | error(message('MATLAB:makehgtform:InvalidParamTranslateNumeric'));
|
| | 58 | end
|
| | 59 | y = double(varargin{ai});
|
| | 60 | ai = ai+1;
|
| | 61 |
|
| | 62 | if ~isnumeric(varargin{ai})
|
| | 63 | error(message('MATLAB:makehgtform:InvalidParamTranslateNumeric'));
|
| | 64 | end
|
| | 65 | z = double(varargin{ai});
|
| | 66 | ai = ai+1;
|
| | 67 | if (~isscalar(y) || ~isscalar(z))
|
| | 68 | %todo
|
| | 69 | end
|
| | 70 |
|
< 0.001 | 154 | 71 | elseif (~isvector(x) || length(x) ~= 3)
|
| | 72 | error(message('MATLAB:makehgtform:InvalidParamTranslate3D'));
|
< 0.001 | 154 | 73 | else
|
< 0.001 | 154 | 74 | y = x(2);
|
< 0.001 | 154 | 75 | z = x(3);
|
< 0.001 | 154 | 76 | x = x(1);
|
< 0.001 | 154 | 77 | end
|
| | 78 |
|
< 0.001 | 154 | 79 | if (~isfinite(x) || ~isfinite(y) || ~isfinite(z))
|
| | 80 | error(message('MATLAB:makehgtform:InvalidParamTranslateFinite'));
|
< 0.001 | 154 | 81 | end
|
0.009 | 154 | 82 | m = matrixMultiply(m,...
|
| 154 | 83 | [1 0 0 x; ...
|
| 154 | 84 | 0 1 0 y; ...
|
| 154 | 85 | 0 0 1 z; ...
|
| | 86 | 0 0 0 1]);
|
| | 87 | % m = m * [1 0 0 x; ...
|
| | 88 | % 0 1 0 y; ...
|
| | 89 | % 0 0 1 z; ...
|
| | 90 | % 0 0 0 1];
|
| | 91 |
|
< 0.001 | 154 | 92 | elseif strcmpi(name,'scale')
|
< 0.001 | 154 | 93 | narginchk(ai,inf);
|
| | 94 |
|
< 0.001 | 154 | 95 | if ~isnumeric(varargin{ai})
|
| | 96 | error(message('MATLAB:makehgtform:InvalidParamScaleNumeric'));
|
< 0.001 | 154 | 97 | end
|
0.002 | 154 | 98 | s = double(varargin{ai});
|
< 0.001 | 154 | 99 | ai = ai+1;
|
| | 100 |
|
< 0.001 | 154 | 101 | if isscalar(s)
|
| | 102 | s = repmat(s,1,3);
|
< 0.001 | 154 | 103 | elseif (~isvector(s) || length(s) ~= 3)
|
| | 104 | error(message('MATLAB:makehgtform:InvalidParamScaleFactor1D3D'));
|
< 0.001 | 154 | 105 | end
|
| | 106 |
|
< 0.001 | 154 | 107 | if (~isfinite(s(1)) || ~isfinite(s(2)) || ~isfinite(s(3)))
|
| | 108 | error(message('MATLAB:makehgtform:InvalidParamScaleFactorFinite'));
|
< 0.001 | 154 | 109 | end
|
| | 110 |
|
< 0.001 | 154 | 111 | if (s(1) <= 0 || s(2) <= 0 || s(3) <= 0)
|
| | 112 | error(message('MATLAB:makehgtform:InvalidParamScaleFactorPositive'));
|
< 0.001 | 154 | 113 | end
|
| | 114 |
|
0.004 | 154 | 115 | m = matrixMultiply(m,...
|
| 154 | 116 | [s(1) 0 0 0; ...
|
| 154 | 117 | 0 s(2) 0 0; ...
|
| 154 | 118 | 0 0 s(3) 0; ...
|
| | 119 | 0 0 0 1]);
|
| | 120 | % m = m * [s(1) 0 0 0; ...
|
| | 121 | % 0 s(2) 0 0; ...
|
| | 122 | % 0 0 s(3) 0; ...
|
| | 123 | % 0 0 0 1];
|
| | 124 |
|
| | 125 | elseif strcmpi(name,'xrotate')
|
| | 126 | narginchk(ai,inf);
|
| | 127 |
|
| | 128 | if ~isnumeric(varargin{ai})
|
| | 129 | error(message('MATLAB:makehgtform:InvalidParamXrotateNumeric'));
|
| | 130 | end
|
| | 131 | t = double(varargin{ai});
|
| | 132 | ai = ai+1;
|
| | 133 |
|
| | 134 | if (~isscalar(t))
|
| | 135 | error(message('MATLAB:makehgtform:InvalidParamRotationScalar'));
|
| | 136 | end
|
| | 137 |
|
| | 138 | if (~isfinite(t))
|
| | 139 | error(message('MATLAB:makehgtform:InvalidParamRotationFinite'));
|
| | 140 | end
|
| | 141 | [ct,st] = computeCosAndSin(t);
|
| | 142 | m = matrixMultiply(m,...
|
| | 143 | [1 0 0 0; ...
|
| | 144 | 0 ct -st 0; ...
|
| | 145 | 0 st ct 0; ...
|
| | 146 | 0 0 0 1]);
|
| | 147 | % m = m * [1 0 0 0; ...
|
| | 148 | % 0 ct -st 0; ...
|
| | 149 | % 0 st ct 0; ...
|
| | 150 | % 0 0 0 1];
|
| | 151 |
|
| | 152 | elseif strcmpi(name,'yrotate')
|
| | 153 | narginchk(ai,inf);
|
| | 154 |
|
| | 155 | if ~isnumeric(varargin{ai})
|
| | 156 | error(message('MATLAB:makehgtform:InvalidParamYrotateNumeric'));
|
| | 157 | end
|
| | 158 | t = double(varargin{ai});
|
| | 159 | ai = ai+1;
|
| | 160 |
|
| | 161 | if (~isscalar(t))
|
| | 162 | error(message('MATLAB:makehgtform:InvalidParamRotationScalar'));
|
| | 163 | end
|
| | 164 |
|
| | 165 | if (~isfinite(t))
|
| | 166 | error(message('MATLAB:makehgtform:InvalidParamRotationFinite'));
|
| | 167 | end
|
| | 168 |
|
| | 169 | [ct,st] = computeCosAndSin(t);
|
| | 170 | m = matrixMultiply(m,...
|
| | 171 | [ct 0 st 0; ...
|
| | 172 | 0 1 0 0; ...
|
| | 173 | -st 0 ct 0; ...
|
| | 174 | 0 0 0 1]);
|
| | 175 | % m = m * [ct 0 st 0; ...
|
| | 176 | % 0 1 0 0; ...
|
| | 177 | % -st 0 ct 0; ...
|
| | 178 | % 0 0 0 1];
|
| | 179 |
|
| | 180 | elseif strcmpi(name,'zrotate')
|
| | 181 | narginchk(ai,inf);
|
| | 182 |
|
| | 183 | if ~isnumeric(varargin{ai})
|
| | 184 | error(message('MATLAB:makehgtform:InvalidParamZrotate'));
|
| | 185 | end
|
| | 186 | t = double(varargin{ai});
|
| | 187 | ai = ai+1;
|
| | 188 |
|
| | 189 | if (~isscalar(t))
|
| | 190 | error(message('MATLAB:makehgtform:InvalidParamRotationScalar'));
|
| | 191 | end
|
| | 192 |
|
| | 193 | if (~isfinite(t))
|
| | 194 | error(message('MATLAB:makehgtform:InvalidParamRotationFinite'));
|
| | 195 | end
|
| | 196 |
|
| | 197 | [ct,st] = computeCosAndSin(t);
|
| | 198 | m = matrixMultiply(m,...
|
| | 199 | [ct -st 0 0; ...
|
| | 200 | st ct 0 0; ...
|
| | 201 | 0 0 1 0; ...
|
| | 202 | 0 0 0 1]);
|
| | 203 | % m = m * [ct -st 0 0; ...
|
| | 204 | % st ct 0 0; ...
|
| | 205 | % 0 0 1 0; ...
|
| | 206 | % 0 0 0 1];
|
| | 207 |
|
| | 208 | elseif strcmpi(name,'axisrotate')
|
| | 209 | narginchk(ai+1,inf);
|
| | 210 |
|
| | 211 | if ~isnumeric(varargin{ai})
|
| | 212 | error(message('MATLAB:makehgtform:InvalidParamAxisRotateNumeric'));
|
| | 213 | end
|
| | 214 | u = double(varargin{ai});
|
| | 215 | ai = ai+1;
|
| | 216 |
|
| | 217 | if ~isnumeric(varargin{ai})
|
| | 218 | error(message('MATLAB:makehgtform:InvalidParamAxisRotateNumeric'));
|
| | 219 | end
|
| | 220 | t = double(varargin{ai});
|
| | 221 | ai = ai+1;
|
| | 222 |
|
| | 223 | if ( ~isvector(u) || length(u) ~= 3)
|
| | 224 | error(message('MATLAB:makehgtform:BadAxis3D'));
|
| | 225 | end
|
| | 226 |
|
| | 227 | if (~isfinite(u(1)) || ~isfinite(u(2)) || ~isfinite(u(3)))
|
| | 228 | error(message('MATLAB:makehgtform:BadAxisFinite'));
|
| | 229 | end
|
| | 230 |
|
| | 231 | if (~isscalar(t))
|
| | 232 | error(message('MATLAB:makehgtform:InvalidParamRotationScalar'));
|
| | 233 | end
|
| | 234 |
|
| | 235 | if (~isfinite(t))
|
| | 236 | error(message('MATLAB:makehgtform:InvalidParamRotationFinite'));
|
| | 237 | end
|
| | 238 |
|
| | 239 | u = u./norm(u);
|
| | 240 | [c,s] = computeCosAndSin(t);
|
| | 241 |
|
| | 242 | tmp = eye(4);
|
| | 243 | tmp(1:3,1:3) = c*eye(3) + (1-c)*kron(u,u') + s*SkewSymm(u);
|
| | 244 | m = m * tmp;
|
| | 245 |
|
| | 246 | else
|
| | 247 | if isCharOrString(name)
|
| | 248 | error(message('MATLAB:makehgtform:BadTransformType', name));
|
| | 249 | elseif isnumeric(name)
|
| | 250 | error(message('MATLAB:makehgtform:UnrecognizedArg', num2str( name )));
|
| | 251 | else
|
| | 252 | error(message('MATLAB:makehgtform:InvalidArg'));
|
| | 253 | end
|
< 0.001 | 308 | 254 | end
|
| | 255 |
|
< 0.001 | 308 | 256 | end
|
Other subfunctions in this file are not included in this listing.