MATLAB: Is polyarea giving incorrect results

MATLABpolyareapolygons

Why is polyarea is giving the wrong area for certain polygons?

Best Answer

polyarea requires that the vertices be in the correct order. Changing around the order of the vertices will produce different results.
When trying to find the area of a square who's vertices are:
(0,0) (0,1) (1,1) (1,0)
 
>> polyarea([0 0 1 1], [0 1 0 1])
ans =
0
>> polyarea([0 0 1 1], [0 1 1 0])
ans =
1