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?
댓글 수: 0
채택된 답변
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
댓글 수: 0
추가 답변 (1개)
참고 항목
카테고리
Help Center 및 File Exchange에서 NaNs에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!