How to draw a rectangle over a patch?

19 次查看(过去 30 天)
Hello, I need to draw a rectangle with curved edges over a background that I created using patch(). For the rectangle I am using the function rectangel() because it has a curvature property. I know that other functions have a property like 'layer' that lets me place things on top of others, but rectangle() doesn't have this property. I am open to alternative methods of creating the rounded rectangle or the background so that I can get the final result.
Thanks in advance!

采纳的回答

Jan
Jan 2021-4-21
编辑:Jan 2021-4-21
You can draw into different AXES objects, while the top one is invisible:
FigH = figure;
Axes1H = axes(FigH, 'XLim', [0, 100], 'YLim', [0, 100]);
Axes2H = axes(FigH, 'XLim', [0, 100], 'YLim', [0, 100], ...
'Visible', 'off'); % On top of Axes1H
patch(Axes1H, [20, 20, 80, 80], [10, 90, 90, 10], [1,0,0])
rectangle(Axes2H, 'Position', [10, 40, 80, 30], 'Curvature', 0.5)
  2 个评论
giannit
giannit 2021-5-7
编辑:giannit 2021-5-7
You can decide who stays at top simply using the Z-axis coordinates of patch.
This will plot the same as Jan
Z = 0*ones(1,4);
patch([20, 20, 80, 80], [10, 90, 90, 10], Z, [1,0,0])
rectangle('Position', [10, 40, 80, 30], 'Curvature', 0.5)
while with Z = 1*ones(1,4) it will plot the patch over the rectangle.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Polygons 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by