geom.signedarea
drafting: A = geom.signedarea (P)
Signed area of a simple polygon.
A = geom.signedarea (P) returns the signed area of the
polygon whose vertices are the rows of the -by-2 matrix P, in
the square of the unit of P. Package convention is millimetres, so
the area is in square millimetres.
The polygon is implicitly closed: the last vertex joins the first. An explicitly repeated closing vertex is accepted and ignored.
The sign carries the orientation. A is positive when the vertices run
counter-clockwise and negative when they run clockwise, so
sign (geom.signedarea (P)) is the cheapest orientation test
available, and abs of the result is the plain area.
The result is meaningful only for a simple polygon, that is, one whose edges do not cross. Self-intersecting input returns a number, but not one that means anything.
See also: geom.bbox, geom.centroid, geom.isrectilinear
Source Code: geom.signedarea
The sign carries the orientation, so sign (geom.signedarea (P)) is the cheapest orientation test there is, and abs of it is the plain area.
P = [0, 0; 40, 0; 40, 30; 0, 30]; geom.signedarea (P) # counter-clockwise: positive
ans = 1200
geom.signedarea (flipud (P)) # clockwise: negative
ans = -1200
An L-shape, whose area is not its bounding box
L = [0, 0; 40, 0; 40, 15; 20, 15; 20, 30; 0, 30]; geom.signedarea (L)
ans = 900