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]);![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1776595/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1776595/image.png)
0 件のコメント
採用された回答
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
The word Rotation does not appear at all on the documentation page listing the properties for the object created by the rectangle function.
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)
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
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 Exchange で Surface and Mesh Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!