MATLAB: How to calculate the area of a polygon with outer loops

areapolygonpolygon area

How could you write code to find the area of a polygon with 2 loops, one with vertices going in a clockwise direction and another with its vertices going in an counterclockwise direction (such as a rough figure of 8)? The current code I have written can only calculate for one direction, so the total area I get is of one loop with the area of the other loop subtracted.
The same problem stands for working out the second moment of area of the polygon.

Best Answer

This is how I'd do it:
area = polyarea(X,Y);
Why make it more complicated than it needs to be? It's not required by a homework assignment because you didn't tag it as "homework" - so why use that algorithm when there's a built-in function for it?
Related Question