matRad function to return the rotation / transformation matrix for gantry and/or couch rotation. The Rotation matrix stands for a (1) counter-clockwise, (2) active rotation in the patient coordinate system that is performed on a (4) column vector (by premultiplying the matrix). Per change of one of these directions a matrix transpose of the returned matrix is required. call rotMat = matRad_getRotationMatrix(gantryAngle,couchAngle,type,system) input gantryAngle: beam/gantry angle couchAngle: couch angle system: optional coordinate system the transformation matrix is requested for. So far, only the default option 'LPS' is supported (right handed system). output rotMat: 3x3 matrix that performs an active rotation around the patient system origin via rotMat * x References https://en.wikipedia.org/wiki/Rotation_matrix (2017, Mar 1) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Copyright 2015 the matRad development team. This file is part of the matRad project. It is subject to the license terms in the LICENSE file found in the top-level directory of this distribution and at https://github.com/e0404/matRad/LICENSES.txt. No part of the matRad project, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the LICENSE file. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0001 function rotMat = matRad_getRotationMatrix(gantryAngle,couchAngle,system) 0002 % matRad function to return the rotation / transformation matrix 0003 % for gantry and/or couch rotation. The Rotation matrix stands for a (1) 0004 % counter-clockwise, (2) active rotation in the patient coordinate system 0005 % that is performed on a (4) column vector (by premultiplying the matrix). 0006 % Per change of one of these directions a matrix transpose of the returned 0007 % matrix is required. 0008 % 0009 % 0010 % call 0011 % rotMat = matRad_getRotationMatrix(gantryAngle,couchAngle,type,system) 0012 % 0013 % input 0014 % gantryAngle: beam/gantry angle 0015 % couchAngle: couch angle 0016 % 0017 % system: optional coordinate system the transformation matrix is 0018 % requested for. So far, only the default option 'LPS' is 0019 % supported (right handed system). 0020 % 0021 % output 0022 % rotMat: 3x3 matrix that performs an active rotation around the 0023 % patient system origin via rotMat * x 0024 % 0025 % References 0026 % https://en.wikipedia.org/wiki/Rotation_matrix (2017, Mar 1) 0027 % 0028 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0029 % 0030 % Copyright 2015 the matRad development team. 0031 % 0032 % This file is part of the matRad project. It is subject to the license 0033 % terms in the LICENSE file found in the top-level directory of this 0034 % distribution and at https://github.com/e0404/matRad/LICENSES.txt. No part 0035 % of the matRad project, including this file, may be copied, modified, 0036 % propagated, or distributed except according to the terms contained in the 0037 % LICENSE file. 0038 % 0039 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0040 0041 %% Parse arguments 0042 %We need at least two and max 3 input arguments 0043 narginchk(2,3); 0044 0045 % Coordinate System (only LPS so far) 0046 if nargin < 3 0047 system = 'LPS'; 0048 end 0049 0050 %% Set Up requested Rotation Matrix 0051 switch system 0052 case 'LPS' 0053 %The LPS system is right-handed, gantry rotates counter-clockwise 0054 %around z and couch rotates counter-clockwise around y 0055 0056 %active, counter-clockwise rotation Matrix for Gantry around z 0057 %with pre-multiplication of the matrix (R*x) 0058 %Note: Gantry rotation is physically an active rotation of a beam 0059 %vector around the target / isocenterin the patient coordinate 0060 %system 0061 R_Gantry = [cosd(gantryAngle) -sind(gantryAngle) 0; ... 0062 sind(gantryAngle) cosd(gantryAngle) 0; ... 0063 0 0 1]; 0064 0065 %active, counter-clockwise rotation for couch around y 0066 %with pre-multiplication of the matrix (R*x) 0067 %Note: Couch rotation is physically a passive rotation of the 0068 %patient system around the beam target point / isocenter 0069 R_Couch = [cosd(couchAngle) 0 sind(couchAngle); ... 0070 0 1 0; ... 0071 -sind(couchAngle) 0 cosd(couchAngle)]; 0072 otherwise 0073 error('matRad only supports LPS system so far'); 0074 end 0075 0076 rotMat = R_Couch*R_Gantry; 0077 0078 end 0079