Example #1
0
 public static bool IsConvexPolyIntersect(Vector3[] poly1, Vector3[] poly2)
 {
     for (int i = 0; i < poly1.Length; ++i)
     {
         if (IsPointInConvexPoly(poly1[i], poly2))
         {
             return(true);
         }
     }
     for (int i = 0; i < poly2.Length; ++i)
     {
         if (IsPointInConvexPoly(poly2[i], poly1))
         {
             return(true);
         }
     }
     for (int i = 0; i < poly1.Length; ++i)
     {
         // test line (poly1[i], poly1[(i + 1) % poly1.Length])
         for (int j = 0; j < poly2.Length; ++j)
         {
             // test line (poly2[j], poly2[(j + 1) % poly2.Length])
             if (IsLineIntersect(poly1[i], poly1[EditorTool.GetValidIndex((i + 1), poly1.Length)], poly2[j], poly2[EditorTool.GetValidIndex((j + 1), poly2.Length)]))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Example #2
0
        public static bool IsPointInConvexPoly(Vector3 p, Vector3[] poly)
        {
            for (int i = 0; i < poly.Length; ++i)
            {
                float cwv = ClockWiseTest(poly[i], poly[EditorTool.GetValidIndex((i + 1), poly.Length)], poly[EditorTool.GetValidIndex((i + 2), poly.Length)]);

                if (cwv < float.Epsilon || ClockWiseTest(p, poly[i], poly[EditorTool.GetValidIndex((i + 1), poly.Length)]) * cwv < 0)
                {
                    return(false);
                }
            }
            return(true);
        }