Patch Between two curves that are not functions. Crosses over

3 次查看(过去 30 天)
I am having trouble fillling the area between {x1, y1} and {x2, y2} without it crossing over. Ideally it should be a filled Elbow shape without crossing over each other. I tried patch and fill functions and I get similair behavior.
x1 = [1 1 1 2.5 5];
y1 = [5 2.5 1 1 1];
x2 = [2 2 5];
y2 = [5 2 2];
hold on
plot(x1, y1, LineStyle=":");
plot(x2, y2, LineStyle=":");
xlim([0, 6])
ylim([0, 6])
fill([x1, x2], [y1, y2], 'k', 'FaceAlpha',0.2)
hold off

采纳的回答

Star Strider
Star Strider 2023-9-14
Perhaps this —
x1 = [1 1 1 2.5 5];
y1 = [5 2.5 1 1 1];
x2 = [2 2 5];
y2 = [5 2 2];
figure
hold on
plot(x1, y1, LineStyle=":");
plot(x2, y2, LineStyle=":");
xlim([0, 6])
ylim([0, 6])
patch([x1 flip(x2)], [y1 flip(y2)], [1 1 1]*0.5, 'EdgeColor','none')
% fill([x1, x2], [y1, y2], 'k', 'FaceAlpha',0.2)
hold off
The patch function fills a closed region, defined by its arguments. If you want to fill between the lines, that is relatively straightforward.
.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Lighting, Transparency, and Shading 的更多信息

产品


版本

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by