The rotation in the rectangle function in matlab cannot be used, but the 2022 version can be used.
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
道夫
el 20 de Sept. de 2024
Comentada: 道夫
el 23 de Sept. de 2024
rectangle('Position',[1 2 5 6],'Rotation',45);
axis([0 10 0 10]);

0 comentarios
Respuesta aceptada
Steven Lord
el 20 de Sept. de 2024
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 comentarios
DGM
el 21 de Sept. de 2024
Editada: DGM
el 21 de Sept. de 2024
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:
Más respuestas (0)
Ver también
Categorías
Más información sobre Elementary Polygons en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


