The rotation in the rectangle function in matlab cannot be used, but the 2022 version can be used.
4 次查看(过去 30 天)
显示 更早的评论
rectangle('Position',[1 2 5 6],'Rotation',45);
axis([0 10 0 10]);

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 中查找有关 Elementary Polygons 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


