How do I rotate a rectangle around its bottom left corner by some angle 'theta_end'?

29 ビュー (過去 30 日間)
Command to create rectangle:
rectangle('Position',[xPos,yPos,W,H]);
xPos and yPos are the x and y positions of the bottom left corner of the rectangle in a 2-D Cartesian system.
I want to rotate the entire rectangle around its bottom left corner by some angle 'theta_end'. The bottom side of the rectangle should form the angle 'theta_end' with the x-axis.
I tried using the rotate command found here ...
r = rectangle('Position',[x_IN_end,y_IN_end,W1,l_F1]);
rRot = rotate(r,theta_end,[0,0,1]);
...but it came back with this message:
Error using rotate
Too many output arguments.

採用された回答

Madeline Gardner
Madeline Gardner 2018 年 6 月 28 日
Hello!
Unfortunately that rotate command is for rectangles created with the Antenna Toolbox, so it won't work for a graphics object rectangle like you've created. Actually, I didn't find any way to directly rotate a rectangle created using that command, though maybe I just didn't see it.
What I did find is that you can use either a patch or a plot and then use this rotate function . Both require specifying the coordinates of the vertices so it's a little less convenient, but they both seem to work.
Example
% p = plot([0 0 20 20 0], [0 40 40 0 0]);
p = patch([0 0 20 20 0], [0 40 40 0 0], [.5 0 .5])
rotate(p, [0 0 1], 45, [0 0 0])
% [0 0 0] is the coordinates of the bottom left corner, which is what you want to rotate around
Hope that helps!
  2 件のコメント
Harry Sood
Harry Sood 2018 年 6 月 28 日
Thanks! It worked like a charm!
Madeline Gardner
Madeline Gardner 2018 年 6 月 28 日
No problem! Glad to hear it!

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

その他の回答 (1 件)

Hang Yu
Hang Yu 2018 年 6 月 28 日
Hi Harry,
Firstly, the rotate function does not return any output, therefore you see the error message "Too many output arguments" when you are expecting the result to be stored in rRot.
Secondly, the rectangle object cannot rotate since there's no property of this object to capture the rotation.
>> doc rectangle
To achieve your goal, please refer to this answer and treat the corners of the rectangle as a set of points.
  2 件のコメント
Harry Sood
Harry Sood 2018 年 6 月 28 日
I used Madeline's solution but thanks for the answer!
Jason Chen
Jason Chen 2018 年 10 月 19 日
rotate() command works for line object but NOT rectangle object. Why it that?

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

カテゴリ

Help Center および File ExchangeAntennas, Microphones, and Sonar Transducers についてさらに検索

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by