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 个)

Adam Danz
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);

David Hill
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
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 CenterFile Exchange 中查找有关 Elementary Polygons 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by