https://github.com/adil192/area_polygon
Calculate the area of a simple 2D polygon given its vertices. This is a port of the math-utils/area-polygon library written in JavaScript.
https://github.com/adil192/area_polygon
dart dart-port flutter js-port math polygons
Last synced: 5 months ago
JSON representation
Calculate the area of a simple 2D polygon given its vertices. This is a port of the math-utils/area-polygon library written in JavaScript.
- Host: GitHub
- URL: https://github.com/adil192/area_polygon
- Owner: adil192
- License: mit
- Created: 2023-10-10T17:40:14.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-05-18T17:38:47.000Z (about 2 years ago)
- Last Synced: 2024-05-18T18:35:50.172Z (about 2 years ago)
- Topics: dart, dart-port, flutter, js-port, math, polygons
- Language: Dart
- Homepage: https://github.com/math-utils/area-polygon
- Size: 22.5 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
Calculate the area of a simple 2D polygon given its vertices.
This is a port of the [math-utils/area-polygon](https://github.com/math-utils/area-polygon)
library written in JavaScript.
## Usage
```dart
List points = [
// your points here, e.g. a 4x4 square:
Offset(0, 0),
Offset(0, 4),
Offset(4, 4),
Offset(4, 0),
];
double area = calculateArea(points); // 16
print('Area: $area');
```
The `points` must also trace the edge of the polygon.
The last point is assumed to be connected to the first point.
If `signed` is true, this will return the signed area.
This is helpful to determine the orientation of `points`.
Signed area is positive if the `points` are counter-clockwise,
or negative if the `points` are clockwise.