MATLAB: Apply Rotation Matrix to a Set of Points

for loopMATLABrotation

Hi all,
I have a set of 3D points (3 by N) to which I am applying a rotation (3 by 3) and translation (1 by 3). I can't figure out a way to get it out of a for-loop, and as you can guess, for loops are too slow.
I currently have:
for i=1:N
rotPoints(:,i) = rotationMatrix*points(:,i)+translationVector;
end
giving me what I want. Tried using bsxfun() with it but no success.
Cheers guys, Andrew

Best Answer

Two options:
(1) Loop over rows instead of columns (a much shorter loop)
rotPoints=rotationMatrix*points;
for i=1:3
rotPoints(i,:) = rotPoints(i,:)+translationVector(i);
end
(2) using BSXFUN
rotPoints=bsxfun(@plus, rotationMatrix*points, translationVector);
Hard to say which will be faster...