protected override void BuildMeshComponents() { Vertices = new Vector3[4]; Vector2 center = MeshHelper.GetCenter(Verts); for (int i = 0; i < 4; i++) { Vertices[i] = Verts[i] - center; } double[] angles = new double[4]; double sum = 0; for (int i = 0; i < 4; i++) { angles[i] = MeshHelper.AngleBetweenPoints(Verts[i], Verts[(i + 1) % 4], Verts[(i + 2) % 4]); sum += angles[i]; } if (System.Math.Abs(360 - sum) < 1e-3) //check for clockwise order { Triangles = new int [] { 0, 1, 3, 2, 3, 1 }; } else { int index = GetMaxIndex(angles); int a = (index + 1) % 4; int b = (index + 2) % 4; int c = (index + 3) % 4; Triangles = new int[] { a, index, c, b, a, c }; } UVs = MeshHelper.UVUnwrap(Vertices); }
public static bool IsShapeClockWise(List<Vector2> sourcePoints) { Debug.Assert(sourcePoints.Count>=3, "Triangulation::IsShapeClockwise: points count must be greater than two!"); double sum = 0; for (int i = 0; i < sourcePoints.Count; i++) { int k1 = i + 1; if (k1 >= sourcePoints.Count) k1 -= sourcePoints.Count; int k2 = i + 2; if (k2 >= sourcePoints.Count) k2 -= sourcePoints.Count; if (AreVecsConvex(sourcePoints[i], sourcePoints[k1], sourcePoints[k2])) { sum += MeshHelper.AngleBetweenPoints(sourcePoints[i], sourcePoints[k1], sourcePoints[k2]); } else { sum += 360 - MeshHelper.AngleBetweenPoints(sourcePoints[i], sourcePoints[k1], sourcePoints[k2]); } } return System.Math.Round(sum) == 180 * (sourcePoints.Count - 2); }