


rotate a polytope of H- or V-representation
Syntax: poly = rotatePolytope(poly, ...)
This function is for 2- and 3-dimensional polytopes only.
The arguments are provided in option/value pairs that are:
'center' uses the given fixed point for rotation. Default: [] (origin
of coordinate system)
'' an empty option name can be used for 2-dimensional rotations
and is followed by the angle in radian.
'x', 3-dimensional polytopes are rotated around these axes with the
'y', 'z' angle given in radian.
'vector' for 3-dimensional polytopes a vector can be provided and the
polytope is rotated so that this vector would match the
z-axis afterwards.
You can append as many rotation operations, as you like.
Example (3D): rotatePolytope(poly, 'x', pi/4, 'center', [1 0 0], ...
'y', pi/4, 'center', [0 0 1], 'z', pi/4)
Example (2D): rotatePolytope(poly, '', pi/4, 'center', [1 1], '', pi/4)
See also: rotateHrep2d, rotateVrep2d, rotateHrep3d, rotateVrep3d,
movePolytope, stretchPolytope

0001 function poly = rotatePolytope(poly, varargin) 0002 % rotate a polytope of H- or V-representation 0003 % 0004 % Syntax: poly = rotatePolytope(poly, ...) 0005 % 0006 % This function is for 2- and 3-dimensional polytopes only. 0007 % 0008 % The arguments are provided in option/value pairs that are: 0009 % 'center' uses the given fixed point for rotation. Default: [] (origin 0010 % of coordinate system) 0011 % '' an empty option name can be used for 2-dimensional rotations 0012 % and is followed by the angle in radian. 0013 % 'x', 3-dimensional polytopes are rotated around these axes with the 0014 % 'y', 'z' angle given in radian. 0015 % 'vector' for 3-dimensional polytopes a vector can be provided and the 0016 % polytope is rotated so that this vector would match the 0017 % z-axis afterwards. 0018 % 0019 % You can append as many rotation operations, as you like. 0020 % 0021 % Example (3D): rotatePolytope(poly, 'x', pi/4, 'center', [1 0 0], ... 0022 % 'y', pi/4, 'center', [0 0 1], 'z', pi/4) 0023 % 0024 % Example (2D): rotatePolytope(poly, '', pi/4, 'center', [1 1], '', pi/4) 0025 % 0026 % See also: rotateHrep2d, rotateVrep2d, rotateHrep3d, rotateVrep3d, 0027 % movePolytope, stretchPolytope 0028 0029 % The elk-library: convex geometry applied to crystallization modeling. 0030 % Copyright (C) 2012 Alexander Reinhold 0031 % 0032 % This program is free software: you can redistribute it and/or modify it 0033 % under the terms of the GNU General Public License as published by the 0034 % Free Software Foundation, either version 3 of the License, or (at your 0035 % option) any later version. 0036 % 0037 % This program is distributed in the hope that it will be useful, but 0038 % WITHOUT ANY WARRANTY; without even the implied warranty of 0039 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0040 % General Public License for more details. 0041 % 0042 % You should have received a copy of the GNU General Public License along 0043 % with this program. If not, see <http://www.gnu.org/licenses/>. 0044 0045 infoP = identifyPolytope(poly); 0046 0047 %% evaluate operations subsequently 0048 x0 = []; 0049 for iArg = 1:2:(nargin-1) 0050 if strcmpi(varargin{iArg}, 'center') 0051 x0 = varargin{iArg+1}; 0052 continue; 0053 end 0054 0055 switch infoP.dim 0056 case 2 0057 switch infoP.rep 0058 case 'Vrep' 0059 poly = rotateVrep2d(poly, varargin{iArg+1}, x0); 0060 case 'Hrep' 0061 poly = rotateHrep2d(poly, varargin{iArg+1}, x0); 0062 end 0063 case 3 0064 switch infoP.rep 0065 case 'Vrep' 0066 poly = rotateVrep3d(poly, varargin{iArg}, varargin{iArg+1}, x0); 0067 case 'Hrep' 0068 poly = rotateHrep3d(poly, varargin{iArg}, varargin{iArg+1}, x0); 0069 end 0070 otherwise 0071 error('elk:polytope:wrongType', ... 0072 'This function is only supported for 2- or 3-dimesnional polytopes'); 0073 end 0074 end 0075 0076 end