フィルターのクリア

Estimating the perimeter of irregular shape

2 ビュー (過去 30 日間)
SAMUEL AYINDE
SAMUEL AYINDE 2018 年 9 月 22 日
コメント済み: Image Analyst 2018 年 9 月 22 日
Please, how can I estimate the perimeter of the shape in this picture, given the x and y coordinates of all the grid points of the geometry. I need a matlab code that will give me a good estimation of the perimeter. Thank you so much.

採用された回答

Nicole Peltier
Nicole Peltier 2018 年 9 月 22 日
My answer assumes that the starting point is the first and last item in the x and y vectors, so if that's not your case, you'll have to add the first point to the end.
x_diff = diff(x);
y_diff = diff(y);
segment_lengths = sqrt(x_diff.^2+y_diff.^2);
perimeter = sum(segment_lengths);
This could be cut down to one line of code, but I wrote it out so you can see each step. You calculate the differences in x and y between each point. The length of each line segment can be calculated according to the Pythagorean theorem (x_diff^2 + y_diff^2 = segment_length^2). The perimeter is the sum of the line segment lengths.
If you're curious, this is how the same code would look when condensed to one line:
perimeter = sum(sqrt(diff(x).^2+diff(y).^2));
Hope this helps!
  1 件のコメント
Image Analyst
Image Analyst 2018 年 9 月 22 日
If you also want to include the length from the last point to the first point, you'll need to tack that on:
x2 = [x, x(1)];
y2 = [y, y(1)];
x_diff = diff(x2);
y_diff = diff(y2);

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeComputational Geometry についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by