pub fn polygon_area<T>(polygon: &ArrayBase<ViewRepr<&T>, Dim<[usize; 2]>>) -> Twhere
T: Float,Expand description
Calculate the area of a simple polygon.
Uses the Shoelace formula (also known as the surveyor’s formula).
§Arguments
polygon- The polygon vertices as an array of [x, y] coordinates
§Returns
- The area of the polygon
§Examples
use scirs2_core::ndarray::array;
use scirs2_spatial::polygon::polygon_area;
// Create a 1x1 square
let square = array![
[0.0, 0.0],
[1.0, 0.0],
[1.0, 1.0],
[0.0, 1.0],
];
let area: f64 = polygon_area(&square.view());
assert!((area - 1.0).abs() < 1e-10);