How to make Rounded Edges of rectangle corners with polyshape function ?

59 次查看(过去 30 天)
hello, everybody
I would like to make the rounded rectangle and I would like them to translated and rotated.
First I tried with rectangle function using 'Curvature' of 1. then I can make the rounded rectangle.
However, it is not possible for them to translated and rotated.
Therefore, I made the rectangle with polyshape function. and it is okay for them to translated and rotated.
However, i do not know how I can make them to have rounded edges.
Could you please helpe me how to make them to rounded edges with polyshape function?
clear; close all; clc;
figure(1); hold on; axis equal
% Before translating and rotating
rectangle('Position',[-14.1276, 226.1976, 6.5929, 9.4184],'FaceColor','r','Curvature',1)
% After translating and rotating
% translate and rotate polygon
x = [-14.1276; -14.1276+6.5929; -14.1276+6.5929; -14.1276];
y = [226.1976; 226.1976; 226.1976+9.4184; 226.1976+9.4184];
p = [x,y];
pgon = polyshape(p);
pgon = translate(pgon,50,-75);
pgon = rotate(pgon,18,[57, 349]);
plot(pgon,'FaceColor','red','FaceAlpha',1)
% object by rectangle function can not translated and rotated.

采纳的回答

DGM
DGM 2022-12-19
I'm pretty sure you can use hgtransform() on rectangle() objects.
hg = hgtransform;
rectangle('parent',hg,'position',[0 0 10 20],'curvature',1);
hg.Matrix = makehgtform('zrotate',pi/6);
axis equal
Alternatively, the following can be used to generate a vertex list that corresponds to the input syntax supported by rectangle(). You can use the vertex data to generate a patch or other type object if you don't want to deal with a rectangle() object.
pos = [0 0 10 20]; % [x y w h]
cur = [1 1]*0.25; % curvature
npts = 20;
npts = round(npts/4)*4 + 1;
th = linspace(0,2*pi,npts);
thm = reshape(th(2:end),[],4);
thm = [th(1) thm(end,1:3); thm];
rr = pos(3:4)/2;
er = cur.*rr;
x = er(1)*cos(thm) + pos(1) + rr(1) + (rr(1)-er(1))*[1 -1 -1 1];
y = er(2)*sin(thm) + pos(2) + rr(2) + (rr(2)-er(2))*[1 1 -1 -1];
x = [x(:); x(1)];
y = [y(:); y(1)];
% plot two identical rounded rectangles atop each other
rectangle('position',pos,'curvature',cur); hold on
plot(x,y,'--y')
axis equal

更多回答(1 个)

S M Ragib Shahriar Islam
Hi, I was also searching for similar type of solution. This following link might help you....

类别

Help CenterFile Exchange 中查找有关 Geometry and Mesh 的更多信息

标签

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by