The rotation in the rectangle function in matlab cannot be used, but the 2022 version can be used.

2 ビュー (過去 30 日間)
rectangle('Position',[1 2 5 6],'Rotation',45);
axis([0 10 0 10]);

採用された回答

Steven Lord
Steven Lord 2024 年 9 月 20 日
try
rectangle('Position',[1 2 5 6],'Rotation',45);
catch ME
fprintf("This command threw the following error:\n%s", ME.message)
end
This command threw the following error: Unrecognized property Rotation for class Rectangle.
The word Rotation does not appear at all on the documentation page listing the properties for the object created by the rectangle function.
You could create a rectangle and call rotate on it.
There is an object in Image Processing Toolbox, images.roi.Rectangle, that has rotation-related properties. Did you meant to create one of those?
obj = images.roi.Rectangle('Position',[1 2 5 6],'Rotation',45)
obj =
Rectangle with properties: Position: [1 2 5 6] RotationAngle: 45 AspectRatio: 1.2000 Label: '' Use GET to show all properties
Or you could create a polyshape object and call its rotate method.
There are a number of other functions that show up when I search the documentation for "rectangle rotation" -- if you meant to use one of those please clarify which type of object you're trying to use and we may be able to suggest the right approach (or tell you that what you're trying to do isn't supported.)
  5 件のコメント
DGM
DGM 2024 年 9 月 21 日
編集済み: DGM 2024 年 9 月 21 日
The rotate() function does not work on rectangle objects.
hr = rectangle('Position',[1 2 5 6]);
rotate(hr,[0 0 1],45) % does nothing
axis equal
You can use hgtransform on rectangle objects:
% initial rectangle parameters
rsize = [5 7]; % [w h]
center = [3.5 5]; % [x y]
% cycle parameters
offset = [8 0]; % [x y]
anglerange = [0 90];
nsteps = 7;
% draw a sequence of rectangles
angles = linspace(anglerange(1),anglerange(2),nsteps);
g = gobjects(nsteps,1);
hr = gobjects(nsteps,1);
for k = 1:nsteps
g(k) = hgtransform;
hr(k) = rectangle('Position',[-rsize/2 rsize],'parent',g(k),'facecolor','r');
Mrot = makehgtform('zrotate',deg2rad(angles(k)));
Mtrans = makehgtform('translate',[(center + (k-1)*offset) 0]);
g(k).Matrix = Mtrans*Mrot;
hold on
end
axis equal
... or you can use rotate() on patch() objects (or polyshapes)
% initial rectangle parameters
rsize = [5 7]; % [w h]
center = [3.5 5]; % [x y]
% cycle parameters
offset = [8 0]; % [x y]
anglerange = [0 90];
nsteps = 7;
% draw a sequence of rectangles
angles = linspace(anglerange(1),anglerange(2),nsteps);
hr = gobjects(nsteps,1);
for k = 1:nsteps
thisc = center + (k-1)*offset;
vx = thisc(1) + [-1 1 1 -1]*rsize(1)/2;
vy = thisc(2) + [-1 -1 1 1]*rsize(2)/2;
hr(k) = patch(vx,vy,'r');
rotate(hr(k),[0 0 1],angles(k),[thisc 0]);
hold on
end
axis equal
See also:

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

タグ

製品


リリース

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by