示例#1
0
        public bool Intersects(Segment s)
        {
            Vector3D i1 = Vector3D.DneVector(), i2 = Vector3D.DneVector();
            int      numInt = 0;

            if (SegmentType.Arc == Type)
            {
                if (SegmentType.Arc == s.Type)
                {
                    numInt = Euclidean2D.IntersectionCircleCircle(Circle, s.Circle, out i1, out i2);
                }
                else
                {
                    numInt = Euclidean2D.IntersectionLineCircle(P1, P2, s.Circle, out i1, out i2);
                }
            }
            else
            {
                if (SegmentType.Arc == s.Type)
                {
                    numInt = Euclidean2D.IntersectionLineCircle(s.P1, s.P2, Circle, out i1, out i2);
                }
                else
                {
                    numInt = Euclidean2D.IntersectionLineLine(P1, P2, s.P1, s.P2, out i1);
                }
            }

            // -1 can denote conincident segments (I'm not consistent in the impls above :/),
            // and we are not going to include those for now.
            if (numInt <= 0)
            {
                return(false);
            }

            if (numInt > 0)
            {
                if (IsPointOn(i1) && s.IsPointOn(i1))
                {
                    return(true);
                }
            }
            if (numInt > 1)
            {
                if (IsPointOn(i2) && s.IsPointOn(i2))
                {
                    return(true);
                }
            }

            return(false);
        }
示例#2
0
        // Get the intersection points with a segment.
        // Returns null if the segment is an arc coincident with the circle (infinite number of intersection points).
        public Vector3D[] GetIntersectionPoints(Segment segment)
        {
            Vector3D p1, p2;
            int      result;

            // Are we a line?
            if (this.IsLine)
            {
                if (SegmentType.Arc == segment.Type)
                {
                    Circle tempCircle = segment.Circle;
                    result = Euclidean2D.IntersectionLineCircle(this.P1, this.P2, tempCircle, out p1, out p2);
                }
                else
                {
                    result = Euclidean2D.IntersectionLineLine(this.P1, this.P2, segment.P1, segment.P2, out p1);
                    p2     = Vector3D.DneVector();
                }
            }
            else
            {
                if (SegmentType.Arc == segment.Type)
                {
                    Circle tempCircle = segment.Circle;
                    result = Euclidean2D.IntersectionCircleCircle(tempCircle, this, out p1, out p2);
                }
                else
                {
                    result = Euclidean2D.IntersectionLineCircle(segment.P1, segment.P2, this, out p1, out p2);
                }
            }

            if (-1 == result)
            {
                return(null);
            }

            List <Vector3D> ret = new List <Vector3D>();

            if (result >= 1 && segment.IsPointOn(p1))
            {
                ret.Add(p1);
            }
            if (result >= 2 && segment.IsPointOn(p2))
            {
                ret.Add(p2);
            }

            return(ret.ToArray());
        }