Example #1
0
        /// <summary>
        /// Touch check between 2 faces. Currently only returns true/false. Should be improved with a new face that overlap between the 2 input faces
        /// </summary>
        /// <param name="F1">Face 1</param>
        /// <param name="F2">Face 2</param>
        /// <returns></returns>
        public static bool touch(Face3D F1, Face3D F2)
        {
            if (Vector3D.Parallels(F1._basePlane.normalVector, F2._basePlane.normalVector))
            {
                // test for any point inside another face
                for (int i = 0; i < F2._vertices.Count; i++)
                {
                    if (Face3D.inside(F1, F2._vertices[i]))
                    {
                        return(true);
                    }
                }
                for (int i = 0; i < F1._vertices.Count; i++)
                {
                    if (Face3D.inside(F2, F1._vertices[i]))
                    {
                        return(true);
                    }
                }
                // if still not returning true, test whether the edges intersect
                List <Point3D> intPoints = new List <Point3D>();
                for (int i = 0; i < F2.boundaries.Count; ++i)
                {
                    if (Face3D.intersect(F1, F2.boundaries[i], out intPoints))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Example #2
0
        /// <summary>
        /// Calculating intersection beween 2 Faces. The outcome of the intersection should be a LineSegment
        /// </summary>
        /// <param name="F1">First Face</param>
        /// <param name="F2">Second Face</param>
        /// <param name="intersectionLine">The resulting intersection line. Zero if no intersection</param>
        /// <param name="mode">The mode of the intersection: No intersection/parallel, partially intersect, no actual intersection/undefined</param>
        /// <returns></returns>
        public static bool intersect(Face3D F1, Face3D F2, out LineSegment3D intersectionLine, out FaceIntersectEnum mode)
        {
            intersectionLine = new LineSegment3D(new Point3D(0, 0, 0), new Point3D(0, 0, 0));
            mode             = FaceIntersectEnum.Undefined;

            if (F1._basePlane.normalVector == F2._basePlane.normalVector)
            {
                // test points inside another face
                for (int i = 0; i < F2._vertices.Count; i++)
                {
                    if (!Face3D.inside(F1, F2._vertices[i]))
                    {
                        continue;
                    }
                    mode = FaceIntersectEnum.Overlap;
                    return(true);
                }
                mode = FaceIntersectEnum.NoIntersectionParallel;
                return(false);
            }

            LineSegment3D ls1;
            LineSegment3D ls2;
            bool          res1 = Plane3D.PPintersect(F1._basePlane, F2, out ls1);
            bool          res2 = Plane3D.PPintersect(F2._basePlane, F1, out ls2);

            if (!res1 || !res2)
            {
                return(false);       // the faces do not intersect
            }
            // Special case if the intersection occurs only at a single point
            if (ls1.startPoint == ls1.endPoint && ls2.startPoint == ls2.endPoint)
            {
                if (ls1.startPoint.Equals(ls2.startPoint))
                {
                    mode = FaceIntersectEnum.IntersectPartial;
                    return(true);
                }
                return(false);
            }
            else if (ls1.startPoint.Equals(ls1.endPoint))
            {
                // a single point intersection: ls1 is 0 length linesegnment = point
                if (LineSegment3D.isInSegment(ls2, ls1.startPoint))
                {
                    mode = FaceIntersectEnum.IntersectPartial;
                    return(true);
                }
                return(false);
            }
            else if (ls2.startPoint.Equals(ls2.endPoint))
            {
                // a single point intersection: ls1 is 0 length linesegnment = point
                if (LineSegment3D.isInSegment(ls1, ls2.startPoint))
                {
                    mode = FaceIntersectEnum.IntersectPartial;
                    return(true);
                }
                return(false);
            }

            LineSegment3D          ovSegment;
            LineSegmentOverlapEnum ovstat = LineSegmentOverlapEnum.Undefined;
            bool lint = LineSegment3D.overlap(ls1, ls2, out ovSegment, out ovstat);

            if (lint)
            {
                intersectionLine = ovSegment;
                mode             = FaceIntersectEnum.IntersectPartial;
                return(true);
            }
            return(false);
        }