bonk-docs/content/shapes/polygon.md

40 lines
898 B
Markdown
Raw Permalink Normal View History

2019-09-15 04:24:36 +00:00
---
title: "Polygon"
date: 2019-09-14T20:55:54-07:00
weight: 40
---
To define a polygon, pass a variable number of **Position2D** structs representing the points of the polygon.
```cs
2019-12-02 06:43:33 +00:00
var polygon = new Polygon(
new Position2D(-2, 0),
new Position2D(0, 2),
new Position2D(2, 0),
);
2019-09-15 04:24:36 +00:00
```
2019-09-15 20:40:00 +00:00
This polygon, for example, is a triangle.
2019-12-02 06:43:33 +00:00
Be careful not to define a concave Polygon, as this will cause the results of collision detection to be incorrect. Support for concave polygons is planned for a future release.
2019-10-25 21:37:17 +00:00
2020-07-18 20:13:59 +00:00
Polygons are considered equal if they define the same vertices, regardless of order.
2019-12-02 06:43:33 +00:00
```cs
var a = new Polygon(
new Position2D(1, 1),
new Position2D(1, -1),
new Position2D(-1, -1),
new Position2D(-1, 1)
);
2020-07-18 20:13:59 +00:00
var b = new Polygon(
new Position2D(-1, 1),
new Position2D(1, 1),
new Position2D(1, -1),
new Position2D(-1, -1)
);
2019-12-02 06:43:33 +00:00
a == b; // true!
```