Example #1
0
        //            top
        // shared1  _______   off1
        //         |
        //   mid   |
        //         |_________   off2
        //            bottom
        private static Segment AcquireMiddleSegment(Segment seg1, Segment seg2, Segment seg3, out Segment top, out Segment bottom)
        {
            if (seg1.SharedVertex(seg2) != null && seg1.SharedVertex(seg3) != null)
            {
                top    = seg2;
                bottom = seg3;
                return(seg1);
            }

            if (seg2.SharedVertex(seg1) != null && seg2.SharedVertex(seg3) != null)
            {
                top    = seg1;
                bottom = seg3;
                return(seg2);
            }

            if (seg3.SharedVertex(seg1) != null && seg3.SharedVertex(seg2) != null)
            {
                top    = seg1;
                bottom = seg2;
                return(seg3);
            }

            top    = null;
            bottom = null;

            return(null);
        }
Example #2
0
        //
        // Do these segments overlay this angle?
        //
        public bool IsIncludedAngle(Segment seg1, Segment seg2)
        {
            // Do not allow the same segment.
            if (seg1.StructurallyEquals(seg2))
            {
                return(false);
            }

            // Check direct inclusion
            if (seg1.Equals(ray1) && seg2.Equals(ray2) || seg1.Equals(ray2) && seg2.Equals(ray1))
            {
                return(true);
            }

            // Check overlaying angle
            Point shared = seg1.SharedVertex(seg2);

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

            Angle thatAngle = new Angle(seg1.OtherPoint(shared), shared, seg2.OtherPoint(shared));

            return(this.Equates(thatAngle));
        }
Example #3
0
        private static Polygon ActuallyConstructThePolygonObject(List <Segment> orderedSides)
        {
            //
            // Check for lines that are actually collinear (and can be compressed into a single segment).
            //
            bool change = true;

            while (change)
            {
                change = false;
                for (int s = 0; s < orderedSides.Count; s++)
                {
                    Segment first  = orderedSides[s];
                    Segment second = orderedSides[(s + 1) % orderedSides.Count];
                    Point   shared = first.SharedVertex(second);

                    // We know these lines share an endpoint and that they are collinear.
                    if (first.IsCollinearWith(second))
                    {
                        Segment newSegment = new Segment(first.OtherPoint(shared), second.OtherPoint(shared));

                        // Replace the two original lines with the new line.
                        orderedSides.Insert(s, newSegment);
                        orderedSides.Remove(first);
                        orderedSides.Remove(second);
                        change = true;
                    }
                }
            }

            KeyValuePair <List <Point>, List <Angle> > pair = MakePointsAngle(orderedSides);

            // If the polygon is concave, make that object.
            if (IsConcavePolygon(pair.Key))
            {
                return(new ConcavePolygon(orderedSides, pair.Key, pair.Value));
            }

            // Otherwise, make the other polygons
            switch (orderedSides.Count)
            {
            case 3:
                return(new Triangle(orderedSides));

            case 4:
                return(Quadrilateral.GenerateQuadrilateral(orderedSides));

            default:
                return(new Polygon(orderedSides, pair.Key, pair.Value));
            }

            //return null;
        }
Example #4
0
        public Angle(Segment ray1, Segment ray2)
            : base()
        {
            Point vertex = ray1.SharedVertex(ray2);

            if (vertex == null) throw new ArgumentException("Rays do not share a vertex: " + ray1 + " " + ray2);

            this.A = ray1.OtherPoint(vertex);
            this.B = vertex;
            this.C = ray2.OtherPoint(vertex);
            this.ray1 = ray1;
            this.ray2 = ray2;
            this.measure = toDegrees(findAngle(A, B, C));

            if (measure <= 0)
            {
                //System.Diagnostics.Debug.WriteLine("NO-OP");
            //                throw new ArgumentException("Measure of " + this.ToString() + " is ZERO");
            }
        }
Example #5
0
        public Angle(Segment ray1, Segment ray2) : base()
        {
            Point vertex = ray1.SharedVertex(ray2);

            if (vertex == null)
            {
                throw new ArgumentException("Rays do not share a vertex: " + ray1 + " " + ray2);
            }

            this.A       = ray1.OtherPoint(vertex);
            this.B       = vertex;
            this.C       = ray2.OtherPoint(vertex);
            this.ray1    = ray1;
            this.ray2    = ray2;
            this.measure = toDegrees(findAngle(A, B, C));

            if (measure <= 0)
            {
                //System.Diagnostics.Debug.WriteLine("NO-OP");
//                throw new ArgumentException("Measure of " + this.ToString() + " is ZERO");
            }
        }
Example #6
0
        public bool IsIncludedAngle(Segment s1, Segment s2, Angle a)
        {
            if (!HasSegment(s1) || !HasSegment(s2) && !HasAngle(a)) return false;

            // If the shared vertex between the segments is the vertex of this given angle, then
            // the angle is the included angle as desired
            return s1.SharedVertex(s2).Equals(a.GetVertex());
        }
Example #7
0
        public Quadrilateral(Segment left, Segment right, Segment top, Segment bottom) : base()
        {
            //
            // Segments
            //
            this.left   = left;
            this.right  = right;
            this.top    = top;
            this.bottom = bottom;

            orderedSides = new List <Segment>();
            orderedSides.Add(left);
            orderedSides.Add(top);
            orderedSides.Add(right);
            orderedSides.Add(bottom);

            //
            // Points
            //
            this.topLeft = left.SharedVertex(top);
            if (topLeft == null)
            {
                return;
                // throw new ArgumentException("Top left point is invalid: " + top + " " + left);
            }
            this.topRight = right.SharedVertex(top);
            if (topRight == null)
            {
                throw new ArgumentException("Top left point is invalid: " + top + " " + right);
            }

            this.bottomLeft = left.SharedVertex(bottom);
            if (bottomLeft == null)
            {
                throw new ArgumentException("Bottom left point is invalid: " + bottom + " " + left);
            }

            this.bottomRight = right.SharedVertex(bottom);
            if (bottomRight == null)
            {
                throw new ArgumentException("Bottom right point is invalid: " + bottom + " " + right);
            }

            points = new List <Point>();
            points.Add(topLeft);
            points.Add(topRight);
            points.Add(bottomRight);
            points.Add(bottomLeft);

            // Verify that we have 4 unique points
            for (int i = 0; i < points.Count - 1; i++)
            {
                for (int j = i + 1; j < points.Count; j++)
                {
                    if (points[i].StructurallyEquals(points[j]))
                    {
                        throw new ArgumentException("Points of quadrilateral are not distinct: " + points[i] + " " + points[j]);
                    }
                }
            }

            //
            // Diagonals
            //
            this.topLeftBottomRightDiagonal = new Segment(topLeft, bottomRight);
            this.bottomLeftTopRightDiagonal = new Segment(bottomLeft, topRight);
            this.diagonalIntersection       = null;
            triPairTLBR = new KeyValuePair <Triangle, Triangle>(new Triangle(topLeft, bottomLeft, bottomRight), new Triangle(topLeft, topRight, bottomRight));
            triPairBLTR = new KeyValuePair <Triangle, Triangle>(new Triangle(bottomLeft, topLeft, topRight), new Triangle(bottomLeft, bottomRight, topRight));

            //
            // Angles
            //
            this.topLeftAngle     = new Angle(bottomLeft, topLeft, topRight);
            this.topRightAngle    = new Angle(topLeft, topRight, bottomRight);
            this.bottomRightAngle = new Angle(topRight, bottomRight, bottomLeft);
            this.bottomLeftAngle  = new Angle(bottomRight, bottomLeft, topLeft);

            angles = new List <Angle>();
            angles.Add(topLeftAngle);
            angles.Add(topRightAngle);
            angles.Add(bottomLeftAngle);
            angles.Add(bottomRightAngle);

            this.FigureSynthesizerConstructor();

            addSuperFigureToDependencies();
        }
Example #8
0
        public static Quadrilateral GenerateQuadrilateral(Segment s1, Segment s2, Segment s3, Segment s4)
        {
            //    ____
            //   |
            //   |____
            // Check a C shape of 3 segments; the 4th needs to be opposite
            Segment top;
            Segment bottom;
            Segment left = AcquireMiddleSegment(s1, s2, s3, out top, out bottom);

            // Check C for the top, bottom, and right sides
            if (left == null)
            {
                return(null);
            }

            Segment right = s4;

            Segment tempOut1, tempOut2;
            Segment rightMid = AcquireMiddleSegment(top, bottom, right, out tempOut1, out tempOut2);

            // The middle segment we acquired must match the 4th segment
            if (!right.StructurallyEquals(rightMid))
            {
                return(null);
            }

            //
            // The top / bottom cannot cross; bowtie or hourglass shape
            // A valid quadrilateral will have the intersections outside of the quad, that is defined
            // by the order of the three points: intersection and two endpts of the side
            //
            Point intersection = top.FindIntersection(bottom);

            // Check for parallel lines, then in-betweenness
            if (intersection != null && !double.IsNaN(intersection.X) && !double.IsNaN(intersection.Y))
            {
                if (Segment.Between(intersection, top.Point1, top.Point2))
                {
                    return(null);
                }
                if (Segment.Between(intersection, bottom.Point1, bottom.Point2))
                {
                    return(null);
                }
            }

            // The left / right cannot cross; bowtie or hourglass shape
            intersection = left.FindIntersection(right);

            // Check for parallel lines, then in-betweenness
            if (intersection != null && !double.IsNaN(intersection.X) && !double.IsNaN(intersection.Y))
            {
                if (Segment.Between(intersection, left.Point1, left.Point2))
                {
                    return(null);
                }
                if (Segment.Between(intersection, right.Point1, right.Point2))
                {
                    return(null);
                }
            }

            //
            // Verify that we have 4 unique points; And not different shapes (like a star, or triangle with another segment)
            //
            List <Point> pts = new List <Point>();

            pts.Add(left.SharedVertex(top));
            pts.Add(left.SharedVertex(bottom));
            pts.Add(right.SharedVertex(bottom));
            pts.Add(right.SharedVertex(top));
            for (int i = 0; i < pts.Count - 1; i++)
            {
                for (int j = i + 1; j < pts.Count; j++)
                {
                    if (pts[i].StructurallyEquals(pts[j]))
                    {
                        return(null);
                    }
                }
            }

            return(new Quadrilateral(left, right, top, bottom));
        }
Example #9
0
        //            top
        // shared1  _______   off1
        //         |
        //   mid   |
        //         |_________   off2
        //            bottom
        private static Segment AcquireMiddleSegment(Segment seg1, Segment seg2, Segment seg3, out Segment top, out Segment bottom)
        {
            if (seg1.SharedVertex(seg2) != null && seg1.SharedVertex(seg3) != null)
            {
                top = seg2;
                bottom = seg3;
                return seg1;
            }

            if (seg2.SharedVertex(seg1) != null && seg2.SharedVertex(seg3) != null)
            {
                top = seg1;
                bottom = seg3;
                return seg2;
            }

            if (seg3.SharedVertex(seg1) != null && seg3.SharedVertex(seg2) != null)
            {
                top = seg1;
                bottom = seg2;
                return seg3;
            }

            top = null;
            bottom = null;

            return null;
        }
Example #10
0
        public Quadrilateral(Segment left, Segment right, Segment top, Segment bottom)
            : base()
        {
            //
            // Segments
            //
            this.left = left;
            this.right = right;
            this.top = top;
            this.bottom = bottom;

            orderedSides = new List<Segment>();
            orderedSides.Add(left);
            orderedSides.Add(top);
            orderedSides.Add(right);
            orderedSides.Add(bottom);

            //
            // Points
            //
            this.topLeft = left.SharedVertex(top);
            if (topLeft == null)
            {
                return;
                // throw new ArgumentException("Top left point is invalid: " + top + " " + left);
            }
            this.topRight = right.SharedVertex(top);
            if (topRight == null) throw new ArgumentException("Top left point is invalid: " + top + " " + right);

            this.bottomLeft = left.SharedVertex(bottom);
            if (bottomLeft == null) throw new ArgumentException("Bottom left point is invalid: " + bottom + " " + left);

            this.bottomRight = right.SharedVertex(bottom);
            if (bottomRight == null) throw new ArgumentException("Bottom right point is invalid: " + bottom + " " + right);

            points = new List<Point>();
            points.Add(topLeft);
            points.Add(topRight);
            points.Add(bottomRight);
            points.Add(bottomLeft);

            // Verify that we have 4 unique points
            for (int i = 0; i < points.Count - 1; i++)
            {
                for (int j = i + 1; j < points.Count; j++)
                {
                    if (points[i].StructurallyEquals(points[j]))
                    {
                        throw new ArgumentException("Points of quadrilateral are not distinct: " + points[i] + " " + points[j]);
                    }
                }
            }

            //
            // Diagonals
            //
            this.topLeftBottomRightDiagonal = new Segment(topLeft, bottomRight);
            this.bottomLeftTopRightDiagonal = new Segment(bottomLeft, topRight);
            this.diagonalIntersection = null;
            triPairTLBR = new KeyValuePair<Triangle, Triangle>(new Triangle(topLeft, bottomLeft, bottomRight), new Triangle(topLeft, topRight, bottomRight));
            triPairBLTR = new KeyValuePair<Triangle, Triangle>(new Triangle(bottomLeft, topLeft, topRight), new Triangle(bottomLeft, bottomRight, topRight));

            //
            // Angles
            //
            this.topLeftAngle = new Angle(bottomLeft, topLeft, topRight);
            this.topRightAngle = new Angle(topLeft, topRight, bottomRight);
            this.bottomRightAngle = new Angle(topRight, bottomRight, bottomLeft);
            this.bottomLeftAngle = new Angle(bottomRight, bottomLeft, topLeft);

            angles = new List<Angle>();
            angles.Add(topLeftAngle);
            angles.Add(topRightAngle);
            angles.Add(bottomLeftAngle);
            angles.Add(bottomRightAngle);

            this.FigureSynthesizerConstructor();

            addSuperFigureToDependencies();
        }
Example #11
0
        //
        // Do these segments overlay this angle?
        //
        public bool IsIncludedAngle(Segment seg1, Segment seg2)
        {
            // Do not allow the same segment.
            if (seg1.StructurallyEquals(seg2)) return false;

            // Check direct inclusion
            if (seg1.Equals(ray1) && seg2.Equals(ray2) || seg1.Equals(ray2) && seg2.Equals(ray1)) return true;

            // Check overlaying angle
            Point shared = seg1.SharedVertex(seg2);

            if (shared == null) return false;

            Angle thatAngle = new Angle(seg1.OtherPoint(shared), shared, seg2.OtherPoint(shared));

            return this.Equates(thatAngle);
        }