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

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

Antworten (2)

Adam Danz
Adam Danz am 30 Mai 2020
Bearbeitet: Adam Danz am 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 am 31 Mai 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 Kommentar
David Hill
David Hill am 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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Elementary Polygons finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by