Home > rest_20090422 > rest_spm5_files > nic_spm_matrix.m

nic_spm_matrix

PURPOSE ^

returns an affine transformation matrix

SYNOPSIS ^

function [A] = nic_spm_matrix(P)

DESCRIPTION ^

 returns an affine transformation matrix
 FORMAT [A] = spm_matrix(P)
 P(1)  - x translation
 P(2)  - y translation
 P(3)  - z translation
 P(4)  - x rotation about - {pitch} (radians)
 P(5)  - y rotation about - {roll}  (radians)
 P(6)  - z rotation about - {yaw}   (radians)
 P(7)  - x scaling
 P(8)  - y scaling
 P(9)  - z scaling
 P(10) - x affine
 P(11) - y affine
 P(12) - z affine

 A     - affine transformation matrix
___________________________________________________________________________

 spm_matrix returns a matrix defining an orthogonal linear (translation,
 rotation, scaling or affine) transformation given a vector of
 parameters (P).  The transformations are applied in the following order
 (i.e., the opposite to which they are specified):

 1) shear
 2) scale
 3) rotation - yaw, roll & pitch
 4) translation

 SPM uses a PRE-multiplication format i.e. Y = A*X where X and Y are 4 x n
 matrices of n coordinates.

__________________________________________________________________________
 Copyright (C) 2005 Wellcome Department of Imaging Neuroscienic_e

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

nic_spm_matrix.m

SOURCE CODE ^

0001 function [A] = nic_spm_matrix(P)
0002 % returns an affine transformation matrix
0003 % FORMAT [A] = spm_matrix(P)
0004 % P(1)  - x translation
0005 % P(2)  - y translation
0006 % P(3)  - z translation
0007 % P(4)  - x rotation about - {pitch} (radians)
0008 % P(5)  - y rotation about - {roll}  (radians)
0009 % P(6)  - z rotation about - {yaw}   (radians)
0010 % P(7)  - x scaling
0011 % P(8)  - y scaling
0012 % P(9)  - z scaling
0013 % P(10) - x affine
0014 % P(11) - y affine
0015 % P(12) - z affine
0016 %
0017 % A     - affine transformation matrix
0018 %___________________________________________________________________________
0019 %
0020 % spm_matrix returns a matrix defining an orthogonal linear (translation,
0021 % rotation, scaling or affine) transformation given a vector of
0022 % parameters (P).  The transformations are applied in the following order
0023 % (i.e., the opposite to which they are specified):
0024 %
0025 % 1) shear
0026 % 2) scale
0027 % 3) rotation - yaw, roll & pitch
0028 % 4) translation
0029 %
0030 % SPM uses a PRE-multiplication format i.e. Y = A*X where X and Y are 4 x n
0031 % matrices of n coordinates.
0032 %
0033 %__________________________________________________________________________
0034 % Copyright (C) 2005 Wellcome Department of Imaging Neuroscienic_e
0035 
0036 % Karl Friston
0037 % $Id: spm_matrix.m 112 2005-05-04 18:20:52Z john $
0038 
0039 
0040 % pad P with 'null' parameters
0041 %---------------------------------------------------------------------------
0042 q  = [0 0 0 0 0 0 1 1 1 0 0 0];
0043 P  = [P q((length(P) + 1):12)];
0044 
0045 T  =   [1     0     0     P(1);
0046         0     1     0     P(2);
0047         0     0     1     P(3);
0048         0     0     0     1];
0049 
0050 R1  =  [1    0       0          0;
0051         0    cos(P(4))  sin(P(4))  0;
0052         0   -sin(P(4))  cos(P(4))  0;
0053         0    0        0          1];
0054 
0055 R2  =  [cos(P(5))  0       sin(P(5))  0;
0056         0           1    0         0;
0057        -sin(P(5))  0      cos(P(5))  0;
0058         0          0    0          1];
0059 
0060 R3  =  [cos(P(6))   sin(P(6))   0  0;
0061        -sin(P(6))   cos(P(6))   0  0;
0062         0           0           1  0;
0063         0             0        0  1];
0064 
0065 Z   =  [P(7)     0       0        0;
0066         0        P(8)     0        0;
0067         0        0        P(9)     0;
0068         0        0        0        1];
0069 
0070 S   =  [1       P(10)   P(11)   0;
0071         0       1     P(12)   0;
0072         0       0       1    0;
0073         0        0        0        1];
0074 
0075 A = T*R1*R2*R3*Z*S;

Generated on Wed 29-Apr-2009 01:06:38 by m2html © 2005