grains.geometry._polygon_area

grains.geometry._polygon_area(x, y)[source]

Computes the signed area of a non-self-intersecting, possibly concave, polygon.

Directly taken from http://rosettacode.org/wiki/Shoelace_formula_for_polygonal_area#Python

Parameters

x, y (list) – Coordinates of the consecutive vertices of the polygon.

Returns

float – Area of the polygon.

Warning

If numpy vectors are passed as inputs, the resulting area is incorrect! WHY?

Notes

The code is not optimized for speed and for numerical stability. Intended to be used to compute the area of finite element cells, in which case the numerical stability is not an issue (unless the cell is degenerate). As this function is called possibly as many times as the number of cells in the mesh, no input checking is performed.

Examples

>>> _polygon_area([0, 1, 1], [0, 0, 1])
0.5