フィルターのクリア

Rotating a 2 demential shape 30 degrees counter clockwise

3 ビュー (過去 30 日間)
Shaan Ali
Shaan Ali 2016 年 7 月 25 日
コメント済み: Alex 2016 年 7 月 27 日
Hello. I am new to the Matlab community and I was having a bit of trouble rotating an irregular 2 dimensional shape. The coordinates a x = [0 0 2 2 0 -2 -2 0] and y = [0 2 2 3 5 3 1 0]. I have to rotate this 30 degrees counter clockwise on the same axis. Any suggestions? Thanks

回答 (1 件)

Alex
Alex 2016 年 7 月 26 日
編集済み: Alex 2016 年 7 月 26 日
This should rotate the points 30 degrees. R is using the rotation matrix to update the pairs of x,y coordinates.
z = [x; y];
thetad = 30;
R =[cosd(thetad) -sind(thetad); sind(thetad) cosd(thetad)];
for i = 1: 8
z(:,i) = R * z(:,i);
end
plot(z(1,:),z(2,:))
  1 件のコメント
Alex
Alex 2016 年 7 月 27 日
You can also use makehgtform to get the rotation matrix, which could be useful if you needed to perform more transformations on the matrix at once. Just make sure you convert your degrees to radians.
Example:
z = [x;y];
M = makehgtform('zrotate', (pi/6));
for i = 1:8
z(:,i) = M(1:2,1:2) * z(:,i);
end
plot(z(1,:),z(2,:))
Here's some more info for working with makehgtform: http://www.mathworks.com/help/matlab/ref/makehgtform.html

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeGraphics Object Programming についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by