Ejemplo n.º 1
0
        //Orient triangles so they have the correct orientation
        public static void OrientTrianglesClockwise(List <Triangle> triangles)
        {
            for (int i = 0; i < triangles.Count; i++)
            {
                Triangle tri = triangles[i];

                Vector2 v1 = new Vector2(tri.v1.position.x, tri.v1.position.z);
                Vector2 v2 = new Vector2(tri.v2.position.x, tri.v2.position.z);
                Vector2 v3 = new Vector2(tri.v3.position.x, tri.v3.position.z);

                if (!Delaunay.IsTriangleOrientedClockwise(v1, v2, v3))
                {
                    tri.ChangeOrientation();
                }
            }
        }
Ejemplo n.º 2
0
        //Is a quadrilateral convex? Assume no 3 points are colinear and the shape doesnt look like an hourglass
        public static bool IsQuadrilateralConvex(Vector2 a, Vector2 b, Vector2 c, Vector2 d)
        {
            bool isConvex = false;

            bool abc = Delaunay.IsTriangleOrientedClockwise(a, b, c);
            bool abd = Delaunay.IsTriangleOrientedClockwise(a, b, d);
            bool bcd = Delaunay.IsTriangleOrientedClockwise(b, c, d);
            bool cad = Delaunay.IsTriangleOrientedClockwise(c, a, d);

            if (abc && abd && bcd & !cad)
            {
                isConvex = true;
            }
            else if (abc && abd && !bcd & cad)
            {
                isConvex = true;
            }
            else if (abc && !abd && bcd & cad)
            {
                isConvex = true;
            }
            //The opposite sign, which makes everything inverted
            else if (!abc && !abd && !bcd & cad)
            {
                isConvex = true;
            }
            else if (!abc && !abd && bcd & !cad)
            {
                isConvex = true;
            }
            else if (!abc && abd && !bcd & !cad)
            {
                isConvex = true;
            }


            return(isConvex);
        }