How can i create a code which accept the 'peaks' of a quadrilateral and then give me the area of it?(without polyarea)
1 回表示 (過去 30 日間)
古いコメントを表示
How can i create a code which accept the 'peaks' of a quadrilateral and then give me the area of it?(without polyarea)
2 件のコメント
回答 (2 件)
Adam Danz
2020 年 5 月 30 日
編集済み: Adam Danz
2020 年 6 月 8 日
Follow this algorithm. There's a link toward the top of that page that shows how to implement the algorithm in JavaScript. Incidentally, polyarea also uses this algorithm but in vectorized format.
verts = [
1 1;
4 1;
4 2;
1 2;
];
area = 0; % Accumulates area
j = size(verts,1);
for i = 1 : j
area = (verts(j,1)+verts(i,1)) * (verts(j,2)-verts(i,2)) + area;
j = i;
end
finalArea = abs(area/2);
0 件のコメント
David Hill
2020 年 5 月 31 日
I would use the polyshape function or polyarea function
pgon=polyshape([0 2 1 2],[0 2 0 -2]);
a=area(pgon);
plot(pgon);
If you just want the area, then:
a=polyarea([0 2 1 2],[0 2 0 -2]);
1 件のコメント
David Hill
2020 年 6 月 8 日
Must be homework if you do not want to use polyarea. What have you tried? I would use Heron's formula for the area of a triangle and add the two triangle areas.
参考
カテゴリ
Help Center および File Exchange で Elementary Polygons についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!