filling area enclosed by multiple curves

25 ビュー (過去 30 日間)
dileesh pv
dileesh pv 2022 年 7 月 12 日
コメント済み: dileesh pv 2022 年 7 月 12 日
I want to fill an area enclosed by multiple curves. I'm currently using the fill command to achieve it. Below is the figure I'm getting. Ideally, i should get the filled in color only inside the enclosed space (on the right side). Fill command worked for me in my earlier usage. Not sure what is happening here!
xdata and ydata are attached along with. The code I'm using has bee given below;
fileID = fopen('dataX.txt','r');
formatSpec = '%f';
xd = fscanf(fileID,formatSpec);
fileID = fopen('dataY.txt','r');
formatSpec = '%f';
yd = fscanf(fileID,formatSpec);
figure(101)
fill(xd,yd,'g','facealpha',0.3);axis equal
Any clue to sort this out is appreciated.
Thanks
  4 件のコメント
dpb
dpb 2022 年 7 月 12 日
Have you tried reversing the direction? Probably won't matter, but...
Alternatively to figuring out what's wrong here, you could try to draw second patch of the LH side that follows the bifurcation and then the three points and see if can fill it with background color to simulate the effect. A hack, yes, but...
Otherwise try patch() or break the above into mutiple sections -- looks like the pointy ends are confusing area as to what it's trying to enclose.
dileesh pv
dileesh pv 2022 年 7 月 12 日
@dpb.. Yes I tried them all :).. @John D'Errico's solution worked like charm and I will try @Star Strider's suggestion too..
Thanks a lot for your time!

サインインしてコメントする。

採用された回答

John D'Errico
John D'Errico 2022 年 7 月 12 日
編集済み: John D'Errico 2022 年 7 月 12 日
No problem (as long as you use a more capable tool), although it appears you have duplicate points.
X = load('dataX.txt');
Y = load('dataY.txt');
PS = polyshape(X,Y);
Warning: Polyshape has duplicate vertices, intersections, or other inconsistencies that may produce inaccurate or unexpected results. Input data has been modified to create a well-defined polyshape.
plot(PS)
axis equal
  1 件のコメント
dileesh pv
dileesh pv 2022 年 7 月 12 日
編集済み: dileesh pv 2022 年 7 月 12 日
Thanks a lot. It worked smooth. I was creating this shape by combining three curves. Therefore, as you rightly suggested, there could be few overlapping points which might be creating duplicates in the corners. Even though I tried by removing those end points, fill/patch were not giving me desired results.
Thanks again for this solution! It worked for all the cases I was looking for!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by