Example #1
0
        internal static bool DetectSelfIntersections(Double2[][] contours)
        {
            var totalLines = contours.Sum(c => c.Length);
            var la         = new Double2[totalLines];
            var lb         = new Double2[totalLines];

            int k = 0;

            foreach (var contour in contours)
            {
                for (int i = 0; i < contour.Length; i++)
                {
                    la[k + i] = contour[i];
                    lb[k + i] = contour[(i + 1) % contour.Length];
                }
                k += contour.Length;
            }

            for (int j = 0; j < totalLines; j++)
            {
                for (int i = j + 1; i < totalLines; i++)
                {
                    // Check for intersections at the midpoints
                    if (GeometricUtils.SegmentsIntersect(la[i], lb[i], la[j], lb[j], true))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Example #2
0
        public bool Overlaps(Triangle other)
        {
            // Check containment
            if (ContainsPoint(other.A))
            {
                return(true);
            }
            if (ContainsPoint(other.B))
            {
                return(true);
            }
            if (ContainsPoint(other.B))
            {
                return(true);
            }
            if (other.ContainsPoint(A))
            {
                return(true);
            }
            if (other.ContainsPoint(B))
            {
                return(true);
            }
            if (other.ContainsPoint(B))
            {
                return(true);
            }

            // Check overlap
            if (GeometricUtils.SegmentsIntersect(A, B, other.A, other.B))
            {
                return(true);
            }
            if (GeometricUtils.SegmentsIntersect(A, B, other.B, other.C))
            {
                return(true);
            }
            if (GeometricUtils.SegmentsIntersect(A, B, other.C, other.A))
            {
                return(true);
            }
            if (GeometricUtils.SegmentsIntersect(B, C, other.A, other.B))
            {
                return(true);
            }
            if (GeometricUtils.SegmentsIntersect(B, C, other.B, other.C))
            {
                return(true);
            }
            if (GeometricUtils.SegmentsIntersect(B, C, other.C, other.A))
            {
                return(true);
            }
            if (GeometricUtils.SegmentsIntersect(C, A, other.A, other.B))
            {
                return(true);
            }
            if (GeometricUtils.SegmentsIntersect(C, A, other.B, other.C))
            {
                return(true);
            }
            if (GeometricUtils.SegmentsIntersect(C, A, other.C, other.A))
            {
                return(true);
            }

            // Otherwise...
            return(false);
        }