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

조회 수: 42 (최근 30일)
Smithy
Smithy 2022년 12월 19일
댓글: Smithy 2022년 12월 20일
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
Smithy
Smithy 2022년 12월 20일
Thank you very much. It works really well. I really really appreciate with it.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

S M Ragib Shahriar Islam
S M Ragib Shahriar Islam 2022년 12월 19일
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