Exemplo n.º 1
0
        public Point OtherPoint(Segment seg)
        {
            if (seg.HasPoint(A) && seg.HasPoint(B))
            {
                return(C);
            }
            if (seg.HasPoint(A) && seg.HasPoint(C))
            {
                return(B);
            }
            if (seg.HasPoint(B) && seg.HasPoint(C))
            {
                return(A);
            }

            if (seg.PointLiesOn(A) && seg.PointLiesOn(B))
            {
                return(C);
            }
            if (seg.PointLiesOn(A) && seg.PointLiesOn(C))
            {
                return(B);
            }
            if (seg.PointLiesOn(B) && seg.PointLiesOn(C))
            {
                return(A);
            }

            return(null);
        }
Exemplo n.º 2
0
        public bool LooseCrosses(Segment that)
        {
            Point p = this.FindIntersection(that);

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

            if (this.HasPoint(p) || that.HasPoint(p))
            {
                return(false);
            }

            return(LooseBetween(p, this.Point1, this.Point2) && LooseBetween(p, that.Point1, that.Point2));
        }
Exemplo n.º 3
0
        public Point OtherPoint(Segment cs)
        {
            if (!cs.HasPoint(Point1)) return Point1;
            if (!cs.HasPoint(Point2)) return Point2;
            if (!cs.HasPoint(Point3)) return Point3;

            return null;
        }
Exemplo n.º 4
0
        //
        // Is this a direct radius segment where one endpoint originates at the origin and extends outward?
        // Return the exact radius.
        private Segment IsRadius(Segment segment, List<Point> figPoints)
        {
            // The segment must originate from the circle center.
            if (!segment.HasPoint(this.center)) return null;

            // The segment must be at least as long as a radius.
            if (!Utilities.CompareValues(segment.Length, this.radius)) return null;

            Point nonCenterPt = segment.OtherPoint(this.center);

            // Check for a direct radius.
            if (this.PointLiesOn(nonCenterPt)) return segment;

            //
            // Check for an extended segment.
            //
            //                radius
            //      center    _____   circPt
            //
            // Find the exact coordinates of the 'circ' points.
            //
            Point inter1 = null;
            Point inter2 = null;
            this.FindIntersection(segment, out inter1, out inter2);

            Point figPoint = Utilities.GetStructurally<Point>(figPoints, inter1);
            if (figPoint == null) figPoint = Utilities.GetStructurally<Point>(figPoints, inter2);

            return new Segment(center, figPoint);
        }
Exemplo n.º 5
0
        public bool LooseCrosses(Segment that)
        {
            Point p = this.FindIntersection(that);

            if (p == null) return false;

            if (this.HasPoint(p) || that.HasPoint(p)) return false;

            return LooseBetween(p, this.Point1, this.Point2) && LooseBetween(p, that.Point1, that.Point2);
        }
Exemplo n.º 6
0
        public Point OtherPoint(Segment seg)
        {
            if (seg.HasPoint(A) && seg.HasPoint(B)) return C;
            if (seg.HasPoint(A) && seg.HasPoint(C)) return B;
            if (seg.HasPoint(B) && seg.HasPoint(C)) return A;

            if (seg.PointLiesOn(A) && seg.PointLiesOn(B)) return C;
            if (seg.PointLiesOn(A) && seg.PointLiesOn(C)) return B;
            if (seg.PointLiesOn(B) && seg.PointLiesOn(C)) return A;

            return null;
        }
Exemplo n.º 7
0
        //                   top
        //                    o
        //  offStands  oooooooe
        //                    e
        //offEndpoint   eeeeeee
        //                    o
        //                 bottom
        //                       Returns: <offEndpoint, offStands>
        public KeyValuePair <Point, Point> CreatesSimplePIShape(Intersection thatInter)
        {
            KeyValuePair <Point, Point> nullPair = new KeyValuePair <Point, Point>(null, null);

            // A valid transversal is required for this shape
            if (!this.CreatesAValidTransversalWith(thatInter))
            {
                return(nullPair);
            }

            // Restrict to desired combination
            if (this.StandsOnEndpoint() && thatInter.StandsOnEndpoint())
            {
                return(nullPair);
            }

            //
            // Determine which is the stands and which is the endpoint
            //
            Intersection endpointInter = null;
            Intersection standsInter   = null;

            if (this.StandsOnEndpoint() && thatInter.StandsOn())
            {
                endpointInter = this;
                standsInter   = thatInter;
            }
            else if (thatInter.StandsOnEndpoint() && this.StandsOn())
            {
                endpointInter = this;
                standsInter   = thatInter;
            }
            else
            {
                return(nullPair);
            }

            //
            // Avoid Some shapes
            //
            Segment transversal       = this.AcquireTransversal(thatInter);
            Segment transversalStands = standsInter.GetCollinearSegment(transversal);

            Point top    = null;
            Point bottom = null;

            if (Segment.Between(standsInter.intersect, transversalStands.Point1, endpointInter.intersect))
            {
                top    = transversalStands.Point1;
                bottom = transversalStands.Point2;
            }
            else
            {
                top    = transversalStands.Point2;
                bottom = transversalStands.Point1;
            }

            // Avoid: ____  Although this shouldn't happen since both intersections do not stand on endpoints
            //        ____|
            //
            // Also avoid Simple F-Shape
            //
            if (transversal.HasPoint(top) || transversal.HasPoint(bottom))
            {
                return(nullPair);
            }

            // Determine S shape
            Point offStands = standsInter.CreatesTShape();

            Segment parallelEndpoint = endpointInter.OtherSegment(transversal);
            Point   offEndpoint      = parallelEndpoint.OtherPoint(endpointInter.intersect);


            Segment crossingTester = new Segment(offStands, offEndpoint);
            Point   intersection   = transversal.FindIntersection(crossingTester);

            // S-shape    // PI-Shape
            return(transversal.PointLiesOnAndBetweenEndpoints(intersection) ? nullPair : new KeyValuePair <Point, Point>(offEndpoint, offStands));
        }
Exemplo n.º 8
0
        //
        // Creates an F-Shape
        //   top
        //    _____ offEnd     <--- Stands on Endpt
        //   |
        //   |_____ offStands  <--- Stands on
        //   |
        //   |
        //  bottom
        //   Order of non-collinear points is order of intersections: <this, that>
        public KeyValuePair <Point, Point> CreatesFShape(Intersection thatInter)
        {
            KeyValuePair <Point, Point> nullPair = new KeyValuePair <Point, Point>(null, null);

            // A valid transversal is required for this shape
            if (!this.CreatesAValidTransversalWith(thatInter))
            {
                return(nullPair);
            }

            // Avoid both standing on an endpoint
            if (this.StandsOnEndpoint() && thatInter.StandsOnEndpoint())
            {
                return(nullPair);
            }

            Intersection endpt    = null;
            Intersection standsOn = null;

            if (this.StandsOnEndpoint() && thatInter.StandsOn())
            {
                endpt    = this;
                standsOn = thatInter;
            }
            else if (thatInter.StandsOnEndpoint() && this.StandsOn())
            {
                endpt    = thatInter;
                standsOn = this;
            }
            else
            {
                return(nullPair);
            }

            Segment transversal       = this.AcquireTransversal(thatInter);
            Segment transversalStands = standsOn.GetCollinearSegment(transversal);

            //
            // Determine Top and bottom to avoid PI shape
            //
            Point top    = null;
            Point bottom = null;

            if (Segment.Between(standsOn.intersect, transversalStands.Point1, endpt.intersect))
            {
                bottom = transversalStands.Point1;
                top    = transversalStands.Point2;
            }
            else
            {
                bottom = transversalStands.Point2;
                top    = transversalStands.Point1;
            }

            // Avoid: ____  Although this shouldn't happen since both intersections do not stand on endpoints
            //        ____|
            if (transversal.HasPoint(top) && transversal.HasPoint(bottom))
            {
                return(nullPair);
            }

            // Also avoid Simple PI-Shape
            //
            if (!transversal.HasPoint(top) && !transversal.HasPoint(bottom))
            {
                return(nullPair);
            }

            // Find the two points that make the points of the F
            Segment parallelEndPt  = endpt.OtherSegment(transversal);
            Segment parallelStands = standsOn.OtherSegment(transversal);

            Point offEnd    = transversal.PointLiesOn(parallelEndPt.Point1) ? parallelEndPt.Point2 : parallelEndPt.Point1;
            Point offStands = transversal.PointLiesOn(parallelStands.Point1) ? parallelStands.Point2 : parallelStands.Point1;

            // Check this is not a crazy F
            //        _____
            //       |
            //   ____|
            //       |
            //       |
            Point intersection = transversal.FindIntersection(new Segment(offEnd, offStands));

            if (transversal.PointLiesOnAndBetweenEndpoints(intersection))
            {
                return(nullPair);
            }

            // Return in the order of 'off' points: <this, that>
            return(this.Equals(endpt) ? new KeyValuePair <Point, Point>(offEnd, offStands) : new KeyValuePair <Point, Point>(offStands, offEnd));
        }