Borrar filtros
Borrar filtros

finding the area using Shoelace Polygon formula

24 visualizaciones (últimos 30 días)
Kratos
Kratos el 4 de Sept. de 2014
Respondida: Aykut Satici el 4 de Sept. de 2014
function area = shoelace (x,y)
n = length(x);
area = 0;
for i = 1 : n-1
area = area + (x(i) + x(i+1)) * (y(i) - y(i+1));
end
area = abs(area)/2;
end
How do I assign the values of x and y and get the answer on the command windows.

Respuestas (1)

Aykut Satici
Aykut Satici el 4 de Sept. de 2014
I don't think that is quite the right formula.
Using the correct formula, your function would be very similar:
function area = shoelace(x,y)
n = length(x);
xp = [x; x(1)];
yp = [y; y(1)];
area = 0;
for i = 1:n
area = area + det([xp(i), xp(i+1); yp(i), yp(i+1)]);
end
area = 1/2*abs(area);
Then you can call this function with two vectors containing the vertices of any n-gon:
x = rand(100,1);
y = rand(100,1);
shoelace(x,y)
You can check the result by comparing it with MATLAB's built-in function "polyarea"

Categorías

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

Community Treasure Hunt

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

Start Hunting!

Translated by