Module polygon

Module polygon 

Source
Expand description

Polygon metrics: area and centroid for arbitrary planar polygons.

This module provides functions to calculate the signed area and centroid of arbitrary planar polygons using the shoelace formula. The polygon vertices should be ordered either in a clockwise or counter-clockwise direction, and

§Examples

use mesh_geometry::{polygon_area, Point2};
let tri = [
    Point2::new(0.0_f64, 0.0_f64),
    Point2::new(2.0_f64, 0.0_f64),
    Point2::new(1.0_f64, 1.7320508_f64),
];
let area = polygon_area(&tri);
assert!((area - 1.7320508_f64).abs() < 1e-6);

Functions§

polygon_area
Signed area of an arbitrary planar polygon (shoelace formula). Vertices ordered CCW or CW, first and last need not repeat.
polygon_centroid
Centroid of a planar polygon: (Cx, Cy) = (1/(6A)) Σ (xi + xi+1)(xi yi+1 − xi+1 yi)