how to get one shape out of multiple shapes
古いコメントを表示
Hi,
I have multiple shapes I need to merge into a single shape, because I have sets of shapes those I have to merge and compare with each other (put into a one plot).
the set of data is attached and I can plot it like this:
plot(X(:, [1:end 1])', Y(:, [1:end 1])')
let me know, if you know how to do it, thanks.
I got this shape using patch, but it generated a Patch file that I cannot use.
Ideally, I would like my data was interpolated so the final shape will not have sharp edges but be smooth and go down to Y=0.
Help me handle that too if you can. thanks

1 件のコメント
Dyuman Joshi
2023 年 12 月 13 日
"I got this shape using patch, but it generated a Patch file that I cannot use."
You can't use the patch object or you can't use the output generated?
What is the expected output? It will be helpful if you can show an illustration.
採用された回答
その他の回答 (2 件)
Mathieu NOE
2023 年 12 月 13 日
hello
try this

x = double(X(:));
y = double(Y(:));
% remove nan
id = isnan(x) & isnan(y);
x(id) = [];
y(id) = [];
% k = boundary(___,s) specifies shrink factor s using any of the previous syntaxes.
% s is a scalar between 0 and 1. Setting s to 0 gives the convex hull,
% and setting s to 1 gives a compact boundary that envelops the points.
% The default shrink factor is 0.5.
s = 0.1;
k = boundary(x,y,s);
x_out = x(k);
y_out = y(k);
% find lower left "corner" point to make extrapolation towards Y = 0
[mx,ix1] = min(x_out);
my = y_out(ix1);
ind = find(x_out<(mx+1));
slope = mean(diff(y_out(ind))./diff(x_out(ind)));
x_lower_left = mx - my/slope;
% find lower right "corner" point to make extrapolation towards Y = 0
[mx,ix2] = max(x_out);
my = y_out(ix2);
ind = find(x_out>(mx-1));
slope = mean(diff(y_out(ind))./diff(x_out(ind)));
x_lower_right = mx - my/slope;
% add those two new points to x_out and y_out
x_out2 = [x_out(1:ix2-1); x_lower_right; x_out(ix2:ix1); x_lower_left; x_out(ix1+1:end) ] ;
y_out2 = [y_out(1:ix2-1); 0 ; y_out(ix2:ix1); 0 ; y_out(ix1+1:end) ] ;
plot(x,y, '*', x_out, y_out, '-*r', x_out2, y_out2, '-g')
Asliddin Komilov
2023 年 12 月 15 日
0 投票
7 件のコメント
Mathieu NOE
2023 年 12 月 19 日
I got this shape if I still use your command
plot(X(:, [1:end 1])', Y(:, [1:end 1])')
- what do you want to do - simply close the top (flat ?)
- does your requirement "go down to Y=0" still holds ? (even though I cannot really figure out what it should be here )

Asliddin Komilov
2023 年 12 月 19 日
Image Analyst
2023 年 12 月 19 日
You might want to unaccept the answer because some people are probably going to skip over your question because they see it's been marked solved.
DGM
2023 年 12 月 19 日
It's not really clear to me what determines whether convexity and extrapolation are required.
I agree with @Image Analyst. If the question isn't answered, don't pick a solution that doesn't work.
Asliddin Komilov
2023 年 12 月 20 日
編集済み: Asliddin Komilov
2023 年 12 月 20 日
Asliddin Komilov
2023 年 12 月 20 日
編集済み: Asliddin Komilov
2023 年 12 月 20 日
Asliddin Komilov
2023 年 12 月 22 日
カテゴリ
ヘルプ センター および File Exchange で Image Arithmetic についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
