Azzera filtri
Azzera filtri

How to draw a rectangle over a patch?

18 visualizzazioni (ultimi 30 giorni)
Nathaniel Levi Blank
Nathaniel Levi Blank il 21 Apr 2021
Modificato: giannit il 7 Mag 2021
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!

Risposta accettata

Jan
Jan il 21 Apr 2021
Modificato: Jan il 21 Apr 2021
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 Commenti
giannit
giannit il 7 Mag 2021
Modificato: giannit il 7 Mag 2021
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.

Accedi per commentare.

Più risposte (0)

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by