Finding segmented triangle area of polygon

2 ビュー (過去 30 日間)
SeungHyun Cha
SeungHyun Cha 2020 年 6 月 9 日
コメント済み: SeungHyun Cha 2020 年 6 月 14 日
I tried to find out the triangle area in the polygon based on determinant theory.
Here is the reference
I tried to calculate the area of triangles using indeces: function and for-loop.
function area = trianglearea(a)
for i = 2 : length(i)-1;
tri = [a(1,1), a(1,i), a(1,i+1); a(2,1), a(2,i), a(2,i+1); 1, 1, 1];
area = 0.5*det(tri)
end
end
A = [0 10 12 8 6 0; 0 1 4 6 8 0];
trianglearea(A)
then the results is
and workplace is the results of area of triangles do not show each reasults following different i value in for-loop. It just show the final result when i = lengh(a)-1.
How can I display every triangle area..?

採用された回答

Chidvi Modala
Chidvi Modala 2020 年 6 月 12 日
You can make use of the following code to capture the area of each triangle and also to find the area of entire polygon
function [area, totalArea] = trianglearea(a)
area = zeros(length(a)-2,1);
for i = 1 : length(area)
tri = [a(1,1), a(1,i+1), a(1,i+2); a(2,1), a(2,i+1), a(2,i+2); 1, 1, 1];
area(i) = 0.5*det(tri);
end
totalArea = sum(area); % Total Area of polygon
end
  1 件のコメント
SeungHyun Cha
SeungHyun Cha 2020 年 6 月 14 日
Thank you

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

その他の回答 (1 件)

Image Analyst
Image Analyst 2020 年 6 月 12 日
Or simply use polyarea().
  1 件のコメント
SeungHyun Cha
SeungHyun Cha 2020 年 6 月 14 日
Thank you

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

カテゴリ

Help Center および File ExchangeElementary Polygons についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by