1function R = Rzyx(phi,theta,psi)
 2%#codegen
 3
 4% R = Rzyx(phi,theta,psi) computes the Euler angle
 5% rotation matrix R in SO(3) using the zyx convention
 6%
 7% Author:   Thor I. Fossen
 8% Date:     14th June 2001
 9% Revisions: 
10% ________________________________________________________________
11%
12% MSS GNC is a Matlab toolbox for guidance, navigation and control.
13% The toolbox is part of the Marine Systems Simulator (MSS).
14%
15% Copyright (C) 2008 Thor I. Fossen and Tristan Perez
16% 
17% This program is free software: you can redistribute it and/or modify
18% it under the terms of the GNU General Public License as published by
19% the Free Software Foundation, either version 3 of the License, or
20% (at your option) any later version.
21% 
22% This program is distributed in the hope that it will be useful, but
23% WITHOUT ANY WARRANTY; without even the implied warranty of
24% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
25% GNU General Public License for more details.
26% 
27% You should have received a copy of the GNU General Public License
28% along with this program.  If not, see <http://www.gnu.org/licenses/>.
29% 
30% E-mail: contact@marinecontrol.org
31% URL:    <http://www.marinecontrol.org>
32
33cphi = cos(phi);
34sphi = sin(phi);
35cth  = cos(theta);
36sth  = sin(theta);
37cpsi = cos(psi);
38spsi = sin(psi);
39 
40R = [...
41   cpsi*cth  -spsi*cphi+cpsi*sth*sphi  spsi*sphi+cpsi*cphi*sth
42   spsi*cth  cpsi*cphi+sphi*sth*spsi   -cpsi*sphi+sth*spsi*cphi
43   -sth      cth*sphi                  cth*cphi ];