I use the following to create a rectangular box using PATCH,
patch([7 7 5 5], [5 7 7 5], 'r')
axis([0 10 0 10])
I want round corners. I have tried the property LineJoin but it does not do anything.
h.LineJoin = 'round';
So is this possible?

 채택된 답변

Matt J
Matt J 2022년 3월 22일
편집: Matt J 2022년 3월 22일

0 개 추천

You can with polyshape,
h=polybuffer( polyshape([7 7 5 5], [5 7 7 5]),0.5);
plot(h,'FaceColor','r', 'FaceAlpha',0.5)

댓글 수: 1

Great. Thank you.
Also I can control transparency.
plot(h, 'FaceAlpha', 0.1)

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

추가 답변 (1개)

Les Beckham
Les Beckham 2022년 3월 22일
편집: Les Beckham 2022년 3월 22일

1 개 추천

Try this. Adjust the 'curvature' value to adjust the ratio of the round corners to the size of the rectangle (1.0 will result in a circle).
rectangle('position', [5 5 2 2], 'curvature', 0.2, 'facecolor', 'r')
axis equal
axis([0 10 0 10])

댓글 수: 4

Kevin
Kevin 2022년 3월 22일
Actually I also want to adjust transparency (i.e. alpha).
I can adjust alpha property with patch but not with rectangle.
Actually, you can. Use a four element color specification. The fourth element is the alpha.
r = rectangle('position', [5 5 2 2], 'curvature', 0.2, 'facecolor', [1 0 0 0.2]);
axis equal
axis([0 10 0 10])
Kevin
Kevin 2022년 3월 22일
I see. But the forth element is not mentioned in the DOC.
I am hoping that this is not an undocumented feature and it may get removed in the future.
But thanks for mentioning this. I have learnt something new today. Great.
Les Beckham
Les Beckham 2022년 3월 22일
You are welcome.
I did too! I wasn't aware of polyshape or polybuffer. Apparently those were added during the several years that I didn't have a copy of Matlab.

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

카테고리

제품

릴리스

R2022a

질문:

2022년 3월 22일

댓글:

2022년 3월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by