I was searching for methods on how to calculate the area of a polygon and stubled across this: http://www.mathopenref.com/coordpolygonarea.html. $$ \mathop{area} = \left\lvert\frac{(x_1y_2 − y_1x_2) + (x_2y_3 − y_2x_3) + \cdots + (x_ny_1 − y_nx_1)}{2} \right\rvert $$ where $x_1,\ldots,x_n$ are the $x$-coordinates and $y_1,\ldots,y_n$ are the $y$-coordinates of the vertices. It does work and all, yet I do not fully understand why this works.
As far as I can tell you take the area of each triangle between two points. Basically you reapeat the formula of $\frac{1}{2} * h * w$ for each of the triangles and take the sum of them? Yet doesn't this leave a "square" in te center of the polygon that is not taken into account? (Apparently not since the correct answer is produced yet I cannot understand how).
If someone could explain this some more to me I would be grateful.
Let $O$ is the origin. Denote "signed area" of triangle $OAB$: $~~S_{OAB}= \dfrac{1}{2}(x_Ay_B-x_By_A)$.
It can be derived from cross product of vectors $\vec{OA}, \vec{OB}$.
If way $AB$ is $\circlearrowleft$ (if polar angle of $A$ less than polar angle of $B$), then $S_{OAB}>0$ ;
if way $AB$ is $\circlearrowright$ (if polar angle of $A$ greater than polar angle of $B$), then $S_{OAB}<0$.
Now, for each edge $A_jA_{j+1}$ ($j=1,2,\ldots,n$; $A_{n+1}\equiv A_1$) of polygon $A_1A_2\ldots A_n$ we can build $2$ vectors: $\vec{OA_j}$ and $\vec{OA_{j+1}}$.
And "signed area" of polygon (which sign depends on numerating direction) $$ S_{A_1A_2...A_n} = \sum_{j=1}^n S_{OA_jA_{j+1}} = \sum_{j=1}^n \dfrac{1}{2}(x_jy_{j+1}-x_{j+1}y_j) = \dfrac{1}{2}\sum_{j=1}^n (x_jy_{j+1}-x_{j+1}y_j). $$
When positive term adds, then square will increase, when negative, then area will decrease.
We will mark "positive" area as blue, and "negative" as red.
Illustration:
