Rotate co ordinates by a rotation matrix.

2 次查看(过去 30 天)
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
Kye Taylor 2013-4-4
编辑:Kye Taylor 2013-4-4
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

更多回答(1 个)

Andy
Andy 2013-4-4
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.

类别

Help CenterFile Exchange 中查找有关 NaNs 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by