Having trouble rotating rectangle shape

10 ビュー (過去 30 日間)
John Morrell
John Morrell 2019 年 1 月 15 日
コメント済み: John Morrell 2019 年 2 月 6 日
I'm trying to use the rotate function to rotate a rectangle object and display it. I can create the rectangle, and no errors are called when using the rotate function on the handle to the rectangle object, but I cannot figure out how to then display that rotated rectangle to the screen. Also I'm not sure if the handle to the original rectangle would retain that rotation in it. By the way, I know I could solve this in a lot of other ways, like by using patch or fill and using a rotation matrix to transform the coordinates, but that's not really the goal. I just want to know how to use the rotate function in a useful way.
figure(1)
axis('equal')
r = rectangle('position',[1 1 1 2]);
rotate(r, [0 0 1], 30);
refreshdata
drawnow

回答 (1 件)

Akira Agata
Akira Agata 2019 年 1 月 16 日
Input argument of rotate function shall be a surface, patch, line, text, or image object. How about the following?
figure
axis('equal')
h = patch('XData',[1 2 2 1],'YData',[1 1 3 3],'FaceColor','none');
view(3)
rotate(h, [0 0 1], 30)
grid on
rect.png
  1 件のコメント
John Morrell
John Morrell 2019 年 2 月 6 日
Thanks! I didn't realize that there wasn't a rectangle object, but this makes sense now.

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

カテゴリ

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

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by