Esempio n. 1
0
        /// <summary>
        /// Compare function.
        /// </summary>
        public int Compare(C2DPoint P1, C2DPoint P2)
        {
            if (P1 == P2)
            {
                return(0);
            }

            C2DVector Vec1 = new C2DVector(Origin, P1);
            C2DVector Vec2 = new C2DVector(Origin, P2);

            double dAng1 = Vec1.AngleFromNorth();
            double dAng2 = Vec2.AngleFromNorth();

            if (dAng1 > dAng2)
            {
                return(1);
            }
            else if (dAng1 < dAng2)
            {
                return(-1);
            }
            else
            {
                return(0);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Removes the convex hull from the point set given.
        /// Will affect the input set.
        /// </summary>
        /// <param name="Other">The other set.</param>
        public void ExtractConvexHull(C2DPointSet Other)
        {
            Clear();

            if (Other.Count < 4)
            {
                this.ExtractAllOf(Other);
                return;
            }

            C2DPoint ptLeftMost = Other[0];
            int      nLeftMost  = 0;

            // Find left most
            for (int i = 1; i < Other.Count; i++)
            {
                C2DPoint pt = Other[i];
                if (pt.x < ptLeftMost.x)
                {
                    ptLeftMost = pt;
                    nLeftMost  = i;
                }
            }

            Add(Other.ExtractAt(nLeftMost));

            Other.SortByAngleFromNorth(this[0]);

            // Always add the left most and the first of the rest.
            Add(Other.ExtractAt(0));

            // Add others if needed.
            int nIndx = 0;

            C2DPointSet Unused = new C2DPointSet();

            while (nIndx < Other.Count)
            {
                int     nLast    = Count - 1;
                C2DLine LastLine = new C2DLine(this[nLast - 1], this[nLast]);

                C2DVector Test = new C2DVector(this[nLast], Other[nIndx]);

                double dAng = Test.AngleFromNorth();

                if (dAng < LastLine.vector.AngleFromNorth())
                {
                    Unused.Add(ExtractAt(nLast));
                }
                else
                {
                    Add(Other.ExtractAt(nIndx));
                }
            }

            Other.ExtractAllOf(Unused);
        }
Esempio n. 3
0
        /// <summary>
        /// Returns the angle to the right to another vector.
        /// </summary>
        public double AngleToRight(C2DVector Other)
        {
            double Result = Other.AngleFromNorth() - AngleFromNorth();

            if (Result < 0)
            {
                Result += Constants.conTWOPI;
            }

            return(Result);
        }
Esempio n. 4
0
        /// <summary>
        /// Returns the projection of this onto the vector provided, given as the interval on
        /// (or off) the vector. Interval given as distance from the start of the vector.
        /// The vector is equivalent to a line from (0, 0).
        /// </summary>
        /// <param name="Vector">The projection vector.</param>
        /// <param name="Interval">The interval to recieve the result.</param>
        public override void Project(C2DVector Vector, CInterval Interval)
        {
            C2DArc    ThisCopy = new C2DArc(this);
            C2DVector VecCopy  = new C2DVector(Vector);

            double dAng = VecCopy.AngleFromNorth();

            VecCopy.TurnLeft(dAng);
            ThisCopy.RotateToRight(-dAng, new C2DPoint(0, 0));

            C2DRect rect = new C2DRect();

            ThisCopy.GetBoundingRect(rect);

            Interval.dMax = rect.GetTop() - VecCopy.j;
            Interval.dMin = Interval.dMax;

            Interval.ExpandToInclude(rect.GetBottom() - VecCopy.j);
        }
        /// <summary>
        /// Returns the angle to the right to another vector.
        /// </summary>
        public double AngleToRight(C2DVector Other)
        {
            double Result = Other.AngleFromNorth() - AngleFromNorth();
            if (Result < 0) Result += Constants.conTWOPI;

            return Result;
        }
Esempio n. 6
0
        /// <summary>
        /// Returns the projection of this onto the vector provided, given as the interval on
        /// (or off) the vector. Interval given as distance from the start of the vector.
        /// The vector is equivalent to a line from (0, 0).
        /// </summary>
        /// <param name="Vector">The projection vector.</param>
        /// <param name="Interval">The interval to recieve the result.</param>
        public override void Project(C2DVector Vector,  CInterval Interval)
        {
	        C2DArc ThisCopy = new C2DArc(this);
	        C2DVector VecCopy = new C2DVector(Vector);

	        double dAng = VecCopy.AngleFromNorth();

	        VecCopy.TurnLeft(dAng);
	        ThisCopy.RotateToRight( -dAng, new C2DPoint(0, 0));

	        C2DRect rect = new C2DRect();
	        ThisCopy.GetBoundingRect( rect);

	        Interval.dMax = rect.GetTop() - VecCopy.j;
	        Interval.dMin = Interval.dMax;

	        Interval.ExpandToInclude( rect.GetBottom() - VecCopy.j );
        }