Exemple #1
0
        private void GetStartEndPoints(out Point start, out Point end, out double startAngle)
        {
            start      = null;
            end        = null;
            startAngle = -1;

            // Find the first point so we sweep in a counter-clockwise manner.
            double angle1 = Point.GetRadianStandardAngleWithCenter(theCircle.center, endpoint1);
            double angle2 = Point.GetRadianStandardAngleWithCenter(theCircle.center, endpoint2);

            // Define to vectors: vect1: A----->B
            //                    vect2: B----->C
            // Cross product vect1 and vect2.
            // If the result is positive, the sequence A-->B-->C is Counter-clockwise.
            // If the result is negative, the sequence A-->B-->C is clockwise.
            Point vect1 = Point.MakeVector(this.middlePoint, this.endpoint1);
            Point vect2 = Point.MakeVector(this.endpoint2, this.middlePoint);

            if (Point.CrossProduct(vect1, vect2) > 0)
            {
                start      = endpoint1;
                end        = endpoint2;
                startAngle = angle1;
            }
            else
            {
                start      = endpoint2;
                end        = endpoint1;
                startAngle = angle2;
            }
        }
Exemple #2
0
        public static bool CounterClockwise(Point A, Point B, Point C)
        {
            // Define two vectors: vect1: A----->B
            //                     vect2: B----->C
            // Cross product vect1 and vect2.
            // If the result is negative, the sequence A-->B-->C is Counter-clockwise.
            // If the result is positive, the sequence A-->B-->C is clockwise.
            Point vect1 = Point.MakeVector(A, B);
            Point vect2 = Point.MakeVector(B, C);

            return(Point.CrossProduct(vect1, vect2) < 0);
        }
Exemple #3
0
        ////
        //// Force this segment into standard position; only 1st and second quadrants allowed.
        ////
        //public Segment Standardize()
        //{
        //    Point vector = Point.MakeVector(this.Point1, this.Point2);

        //    // If this segment is in the 3rd or 4th quadrant, force into the second by taking the opposite.
        //    if (vector.Y < 0) vector = Point.GetOppositeVector(vector);

        //    return new Segment(origin, vector);
        //}

        public Segment ConstructSegmentByAngle(Point tail, int angle, int length)
        {
            // Make a vector in standard position
            Point vector = Point.MakeVector(tail, this.OtherPoint(tail));

            // Calculate the angle from standard position.
            double stdPosAngle = Point.GetDegreeStandardAngleWithCenter(origin, vector);

            // Get the exact point we want.
            Point rotatedPoint = Figure.GetPointByLengthAndAngleInStandardPosition(length, stdPosAngle - angle);

            return(new Segment(tail, rotatedPoint));
        }
Exemple #4
0
        //
        // Given one of the fixed endpoints on this segment, return a congruent segment with the: fixed endpoint and the other point being moved.
        //
        public Segment GetOppositeSegment(Point pt)
        {
            if (!HasPoint(pt))
            {
                return(null);
            }

            Point fixedPt    = pt;
            Point variablePt = this.OtherPoint(pt);

            Point vector = Point.MakeVector(fixedPt, variablePt);
            Point opp    = Point.GetOppositeVector(vector);

            // 'Move' the vector to begin at its starting point: pt
            return(new Segment(pt, new Point("", pt.X + opp.X, pt.Y + opp.Y)));
        }
Exemple #5
0
        //
        // Return the line perpendicular to this segment at the given point.
        // The point is ON the segment.
        public Segment GetPerpendicularByLength(Point pt, double length)
        {
            Segment perp = this.GetPerpendicular(pt);

            //
            // Find the point which is length distance from the given point.
            //
            // Treat the given perpendicular as a vector; normalize and then multiply.
            //
            Point vector = Point.MakeVector(perp.Point1, perp.Point2);

            vector = Point.Normalize(vector);
            vector = Point.ScalarMultiply(vector, length);

            // 'Move' the vector to begin at its starting point: pt
            // Return the perpendicular of proper length.
            return(new Segment(pt, new Point("", pt.X + vector.X, pt.Y + vector.Y)));
        }
Exemple #6
0
        //
        // Return True if the polygon is convex.
        // http://blog.csharphelper.com/2010/01/04/determine-whether-a-polygon-is-convex-in-c.aspx
        //
        protected static bool IsConcavePolygon(List <Point> orderedPts)
        {
            // For each set of three adjacent points A, B, C,
            // find the dot product AB · BC. If the sign of
            // all the dot products is the same, the angles
            // are all positive or negative (depending on the
            // order in which we visit them) so the polygon
            // is convex.
            bool got_negative = false;
            bool got_positive = false;
            int  B, C;

            for (int A = 0; A < orderedPts.Count; A++)
            {
                B = (A + 1) % orderedPts.Count;
                C = (B + 1) % orderedPts.Count;

                // Create normalized vectors and find the cross-product.
                Point vec1 = Point.MakeVector(orderedPts[A], orderedPts[B]);
                Point vec2 = Point.MakeVector(orderedPts[B], orderedPts[C]);

                double cross_product = Point.CrossProduct(vec1, vec2);

                if (cross_product < 0)
                {
                    got_negative = true;
                }
                else if (cross_product > 0)
                {
                    got_positive = true;
                }
                if (got_negative && got_positive)
                {
                    return(true);
                }
            }

            // If we got this far, the polygon is convex.
            return(false);
        }