# Rotate co ordinates by a rotation matrix.

3 views (last 30 days)
Andy on 4 Apr 2013
I have a set of x and y co ordinates which make up a random shape. I want to be able to rotate the shape 360 degrees in an animation. To do this i want to multiply the co ordinates by a rotation matrix and then i will set the co ordinates of the shape to these which will rotate the shape by that amount.
I have my rotation matrix
rot = [cos(5),sin(5);-sin(5),cos(5)];
and then i try to multiply the coordinates like this.
xCor = rot*xCor; yCor = rot*yCor;
I get an error saying the inner matrix dimensions must agree. How would i go about getting this to work, or is there a better way to achieve this?

Kye Taylor on 4 Apr 2013
Edited: Kye Taylor on 4 Apr 2013
Is that 5 radians or 5 degrees you wish to rotate the points. If it's 5 degrees, I think you mean to have
rot = [cosd(5),sind(5);-sind(5),cosd(5)]
To answer your main question, what is the size of xCor and yCor? They should by 2 -by-N for some positive integer N.
However, I'm assuming that xCor is 1-by-N (x-coordinates of N points) and yCor is 1-by-N (y-coordinates of N points). If that is the case, try this instead
rData = rot*[xCor;yCor]; % compute 2-by-N array of rotated data
rXCor = rData(1,:); % extract x-coordinates of rotated data
rYCor = rData(2,:); % extract y-coordinates of rotated data

Andy on 4 Apr 2013
Hi Kye,
You assumed correctly, i did want to use degrees my co ordinates are 1 by N. All is working great now, thank you for the help.