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 CenterFile Exchange에서 Correlation and Convolution에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by