Skip to main content

Triangles

A static class in Root.Township, the global namespace.

2D triangle helpers: signed area, point in triangle tests, and ear-clipping triangulation of a polygon.

Methods​

MemberWhat it is
static float Area(Vector2 a, Vector2 b, Vector2 c)Signed area of a triangle or of a polygon's points. Positive means counter-clockwise.
static float Area(Vector2[] points)Signed area of a triangle or of a polygon's points. Positive means counter-clockwise.
static bool IsWithin(Vector2 point, Vector2 a, Vector2 b, Vector2 c, out float s, out float t)Whether a point is in a triangle, also giving its barycentric s and t.
static int[] Triangulate(Vector2[] points)Ear-clips a simple polygon into triangle indices, optionally giving its area. Returns what it managed if the polygon is bad.
static int[] Triangulate(Vector2[] points, out float area)Ear-clips a simple polygon into triangle indices, optionally giving its area. Returns what it managed if the polygon is bad.
2 private and internal methods
MemberWhat it is
private static bool InsideTriangle(Vector2 A, Vector2 B, Vector2 C, Vector2 P)Whether a point is inside a triangle (edges count). Used by Snip.
private static bool Snip(Vector2[] points, int u, int v, int w, int n, int[] V)Whether the three given corners form an ear that can be cut off during triangulation.