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

1 visualización (últimos 30 días)
How can i create a code which accept the 'peaks' of a quadrilateral and then give me the area of it?(without polyarea)

Respuestas (2)

Adam Danz
Adam Danz el 30 de Mayo de 2020
Editada: Adam Danz el 8 de Jun. de 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 el 31 de Mayo de 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 comentario
David Hill
David Hill el 8 de Jun. de 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.

Iniciar sesión para comentar.

Categorías

Más información sobre Elementary Polygons en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by