forked from e0404/matRad
-
Notifications
You must be signed in to change notification settings - Fork 0
/
matRad_getRotationMatrix.m
81 lines (72 loc) · 3.01 KB
/
matRad_getRotationMatrix.m
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
function rotMat = matRad_getRotationMatrix(gantryAngle,couchAngle,system)
% 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.
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Parse arguments
%We need at least two and max 3 input arguments
narginchk(2,3);
% Coordinate System (only LPS so far)
if nargin < 3
system = 'LPS';
end
%% Set Up requested Rotation Matrix
switch system
case 'LPS'
%The LPS system is right-handed, gantry rotates counter-clockwise
%around z and couch rotates counter-clockwise around y
%active, counter-clockwise rotation Matrix for Gantry around z
%with pre-multiplication of the matrix (R*x)
%Note: Gantry rotation is physically an active rotation of a beam
%vector around the target / isocenterin the patient coordinate
%system
R_Gantry = [cosd(gantryAngle) -sind(gantryAngle) 0; ...
sind(gantryAngle) cosd(gantryAngle) 0; ...
0 0 1];
%active, counter-clockwise rotation for couch around y
%with pre-multiplication of the matrix (R*x)
%Note: Couch rotation is physically a passive rotation of the
%patient system around the beam target point / isocenter
R_Couch = [cosd(couchAngle) 0 sind(couchAngle); ...
0 1 0; ...
-sind(couchAngle) 0 cosd(couchAngle)];
otherwise
error('matRad only supports LPS system so far');
end
rotMat = R_Couch*R_Gantry;
end