Rotate co ordinates by a rotation matrix.

3 ビュー (過去 30 日間)
Andy
Andy 2013 年 4 月 4 日
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 Center および File ExchangeCorrelation and Convolution についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by