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

44 vues (au cours des 30 derniers jours)
Smithy
Smithy le 19 Déc 2022
Commenté : Smithy le 20 Déc 2022
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.

Réponse acceptée

DGM
DGM le 19 Déc 2022
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 commentaire
Smithy
Smithy le 20 Déc 2022
Thank you very much. It works really well. I really really appreciate with it.

Connectez-vous pour commenter.

Plus de réponses (1)

S M Ragib Shahriar Islam
S M Ragib Shahriar Islam le 19 Déc 2022
Hi, I was also searching for similar type of solution. This following link might help you....

Catégories

En savoir plus sur Elementary Polygons dans Help Center et File Exchange

Tags

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by