How can i create a code which accept the 'peaks' of a quadrilateral and then give me the area of it?(without polyarea)

1 view (last 30 days)
How can i create a code which accept the 'peaks' of a quadrilateral and then give me the area of it?(without polyarea)

Answers (2)

Adam Danz
Adam Danz on 30 May 2020
Edited: Adam Danz on 8 Jun 2020
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 on 31 May 2020
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 Comment
David Hill
David Hill on 8 Jun 2020
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.

Sign in to comment.

Categories

Find more on Elementary Polygons in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!