Asked by John deGrassie
on 7 Mar 2013

I want to rotate a matrix of points, i.e. column vectors. However, I want to rotate each vector in the matrix by a different angle. For example:

pointMatrix = [v1,v2,v3,v4]; %vi is a column vector rotateAngles = [10,20,30,40]; %degrees

Say I want to rotate these points around the z-axis. Therefore, for one point I could do something like the following:

Rz = [[cos(rotateAngles(1)) -sin(rotateAngles(1)) 0];... [sin(rotateAngles(1)) cos(rotateAngles(1)) 0];... [ 0 0 1]]; v1Rotated = Rz*v1;

Is there a non-loop way to rotate all the vectors in my pointMatrix by each one's unique rotation angle? Something like this...

allRotatedPoints = superRotationMatrix*pointMatrix;

where the superRotationMatrix "magically" rotates each column by the corresponding angle.

Thanks!

Answer by Teja Muppirala
on 8 Mar 2013

Edited by Teja Muppirala
on 8 Mar 2013

Accepted answer

This vectorized solution uses complex exponentials and works about 2 orders of magnitude faster for large vectors.

M = exp(rotateAngles*1i) .* ([1 1i 0]*pointMatrix); allRotatedPoints = [real(M); imag(M); pointMatrix(3,:)];

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi test

Learn moreOpportunities for recent engineering grads.

Apply Today
## 0 Comments