Пример #1
0
        //
        // Returns the exact transversal between the intersections
        //
        public Segment AcquireTransversal(Intersection thatInter)
        {
            // The two intersections should not be at the same vertex
            if (intersect.Equals(thatInter.intersect))
            {
                return(null);
            }

            Segment common = CommonSegment(thatInter);

            if (common == null)
            {
                return(null);
            }

            // A legitimate transversal must belong to both intersections (is a subsegment of one of the lines)
            Segment transversal = new Segment(this.intersect, thatInter.intersect);

            Segment thisTransversal = this.GetCollinearSegment(transversal);
            Segment thatTransversal = thatInter.GetCollinearSegment(transversal);

            if (!thisTransversal.HasSubSegment(transversal))
            {
                return(null);
            }
            if (!thatTransversal.HasSubSegment(transversal))
            {
                return(null);
            }

            return(transversal);
        }
Пример #2
0
        public bool CreatesAValidTransversalWith(Intersection thatInter)
        {
            Segment transversal = this.AcquireTransversal(thatInter);

            if (transversal == null)
            {
                return(false);
            }

            // Ensure the non-traversal segments align with the parallel segments
            Segment nonTransversalThis = this.OtherSegment(transversal);
            Segment nonTransversalThat = thatInter.OtherSegment(transversal);

            Segment thisTransversalSegment = this.OtherSegment(nonTransversalThis);
            Segment thatTransversalSegment = thatInter.OtherSegment(nonTransversalThat);

            // Parallel lines should not coincide
            if (nonTransversalThis.IsCollinearWith(nonTransversalThat))
            {
                return(false);
            }

            // Avoid:
            //      |            |
            //    __|    ________|
            //      |            |
            //      |            |

            // Both intersections (transversal segments) must contain the actual transversal
            return(thatTransversalSegment.HasSubSegment(transversal) && thisTransversalSegment.HasSubSegment(transversal));
        }
Пример #3
0
        //
        // Does the given segment contain a radius of this circle?
        //
        public bool ContainsRadiusWithin(Segment thatSegment)
        {
            foreach (Segment radius in radii)
            {
                if (thatSegment.HasSubSegment(radius)) return true;
            }

            return false;
        }
Пример #4
0
        //
        // Does the given segment contain a chord? Return the chord.
        //
        public Segment ContainsChord(Segment thatSegment)
        {
            foreach (KeyValuePair<Segment, Segment> pair in secants)
            {
                // Does the secant contain that segment? If so, is the chord contained in that Segment?
                if (pair.Key.HasSubSegment(thatSegment))
                {
                    if (thatSegment.HasSubSegment(pair.Value)) return pair.Value;
                }
            }

            return null;
        }