Rotate rectangle x number of degrees when using imrect or alternative function
1 回表示 (過去 30 日間)
古いコメントを表示
Hi everybody,
I would like to allow a user to draw a rectangle over a plot to highlight some data. This seems entirely possible using imrect, however I sometimes need the rectangle to be rotated 60 degrees to the x axis. I can't find any mention of rotation in the help or by using get(h).
I've looked for some help on this function but strangely it doesn't seem to be widely used. Does anybody know how to rotate a rectangle when using imrect, or are there alternatives which do allow it?
Thanks,
Rod.
0 件のコメント
採用された回答
Image Analyst
2014 年 4 月 5 日
You can get the vertices of the corners. Then use the rotation matrix (see Wikipedia) to rotate it about its center by any angle. Then redraw the rectangle with plot().
2 件のコメント
Image Analyst
2014 年 4 月 5 日
編集済み: Image Analyst
2014 年 4 月 5 日
Rod, it's trivial. Just a 2 by 2 matrix [cos, -sin, sin, cos] multiplied by the "old" coordinates. See the attached demo to rotate an ellipse, and a star.
rotationArray = [cos(rotationAngle), -sin(rotationAngle); sin(rotationAngle), cos(rotationAngle)];
% Rotate the diagram
rotatedArray = vertices * rotationArray;
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で 3-D Scene Control についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!