Hi
I want to rotate a vector based on change in the spm_vol M matrix (for DTI
data) and came up with the function below, but I am not 100% sure it is
accurate. Could anyone comment on the function's acuuracy of lack thereof?
Thanks,
Paul
function vout = cspm_vectorrotate(vin,Mfrom,Mto)
% Rotates [x y z] vector according to M matrix change
if size(vin,2) == 3, vin = vin'; flip = 1;
else flip = 0; end
prm = spm_imatrix(Mfrom/Mto);
tmp = spm_matrix([0 0 0 prm(4:6) sign(prm(7:9))]);
Mrot = tmp(1:3,1:3);
vout = (Mrot*vin);
if flip, vout = vout'; end
return
|