Exemple #1
0
        public bool isfEqual(XYPT q)
        {
            bool bxeq = (x == q.x ? true : false);
            bool byeq = (y == q.y ? true : false);

            return(bxeq && byeq);
        }
Exemple #2
0
        public bool PointInPolygon(XYPT point)
        {
            int  i, j;
            bool inside = false;
            int  nvert  = m_points.Count;

            for (i = 0, j = nvert - 1; i < nvert; j = i++)
            {
                if (((m_points[i].YY > point.YY) != (m_points[j].YY > point.YY)) &&
                    (point.XX < (m_points[j].XX - m_points[i].XX) * (point.YY - m_points[i].YY) / (m_points[j].YY - m_points[i].YY) + m_points[i].XX))
                {
                    inside = !inside;
                }
            }
            // check if point is over segments of polygon
            if (inside != true)
            {
                for (int k = 0; k < nvert; k++)
                {
                    if (PointOnLineSegment(m_points[(k + 1) % nvert], m_points[k], point))
                    {
                        return(true);
                    }
                }
            }
            return(inside);
        }
Exemple #3
0
 public Line(XYPT pt1, XYPT pt2)
 {
     m_points = new List <XYPT>()
     {
         pt1, pt2
     };
 }
Exemple #4
0
 public void RemovePoint(XYPT p)
 {
     if (ContainsPoint(p))
     {
         m_points.Remove(p);
     }
 }
Exemple #5
0
        /// <summary>
        ///		<para> Imagine a list of column vectors, each bearing a list of XY-points, essentially a 2d matrix.	</para>
        ///		<para> This utility returns the largest X and largest Y value in each row.							</para>
        /// </summary>
        /// <param name="list"> A list of lists of XYPTs </param>
        /// <returns></returns>
        public static XYPT[] MaximumVector(List <List <XYPT> > list)
        {
            /*	Example:
             *
             *	List[0]		List[1]		List[2]					double[] Array
             *	List[0][0]		[1][0]		[2][0]		==>		[0].x = Max{ [0][0].x,  [1][0].x,  [2][0].x };   [0].y = Max{ [0][0].y,  [1][0].y,  [2][0].y }
             *		[0][1]		[1][1]		[2][1]		==>		[1].x = Max{ [1][0].x,  [1][1].x,  [2][1].x };   [1].y = Max{ [0][1].y,  [1][1].y,  [2][1].y }
             *		[0][2]		[1][2]		[2][2]		==>		[2].x = Max{ [2][0].x,  [1][2].x,  [2][2].x };   [2].y = Max{ [0][2].y,  [1][2].y,  [2][2].y }
             *		[0][3]		[1][3]		[2][3]		==>		[3].x = Max{ [3][0].x,  [1][3].x,  [2][3].x };   [3].y = Max{ [0][3].y,  [1][3].y,  [2][3].y }
             *		[0][4]		[1][4]		[2][4]		==>		[4].x = Max{ [4][0].x,  [1][4].x,  [2][4].x };   [4].y = Max{ [0][4].y,  [1][4].y,  [2][4].y }
             */
            int mVectors = list.Count;

            XYPT[] maximum  = new XYPT[0];
            int    nRowsMax = 0;

            if (mVectors <= 0)
            {
                return(maximum);
            }

            for (int iRow = 0; iRow < mVectors; iRow++)
            {
                if (nRowsMax < list[iRow].Count)
                {
                    nRowsMax = list[iRow].Count;
                }
            }

            // Create the array of sums
            maximum = new XYPT[nRowsMax];
            if (nRowsMax <= 0)
            {
                return(maximum);
            }


            for (int iRow = 0; iRow < nRowsMax; iRow++)
            {
                maximum[iRow] = -XYPT.MaxValue;             // Set to the largest negative double.
                for (int jCol = 0; jCol < mVectors; jCol++)
                {
                    int nXYPTs = list[jCol].Count;
                    if (1 <= nXYPTs && nXYPTs <= nRowsMax)
                    {
                        XYPT p = list[jCol][iRow];
                        if (maximum[iRow].x < p.x)
                        {
                            maximum[iRow].x = p.x;
                        }
                        if (maximum[iRow].y < p.y)
                        {
                            maximum[iRow].y = p.y;
                        }
                    }
                }
            } // for( int iRow = 0 ; iRow < nRowsMax ; iRow++ )

            return(maximum);
        } // public static double[] MaximumVectorYs( List<List<XYPT>> list )
Exemple #6
0
        public XYPT Moved(XYPT displacement)
        {
            XYPT asif = this; // asif == "As If"

            asif.x += displacement.x;
            asif.y += displacement.y;
            return(asif);
        }
Exemple #7
0
        public XYPT MidwayPointTo(XYPT p2)
        {
            XYPT p;

            p.x = 0.5f * (this.x + p2.x);
            p.y = 0.5f * (this.y + p2.y);
            return(p);
        }
Exemple #8
0
        public XYPT Midpt(XYPT p2)
        {
            XYPT p;

            p.x = 0.5f * (this.x + p2.x);
            p.y = 0.5f * (this.y + p2.y);
            return(p);
        }
Exemple #9
0
        public XYPT Moved(double r, double phi)
        {
            XYPT asif = this; // asif == "As If"

            asif.x += r * Math.Cos(phi);
            asif.y += r * Math.Sin(phi);
            return(asif);
        }
Exemple #10
0
        public void AddPoint(XYPT p)
        {
            if (m_points == null)
            {
                m_points = new List <XYPT>();
            }

            m_points.Add(p);
        }
Exemple #11
0
        /// <summary>
        ///		Returns q rotated relative p (origin).
        /// </summary>
        /// <param name="q">	The point being rotated.			</param>
        /// <param name="phi">	The angle of rotation (in radians).	</param>
        /// <returns></returns>
        public XYPT Rotated(XYPT q, double phi)
        {
            double cp = Math.Cos(phi);
            double sp = Math.Sin(phi);
            double dx = q.x - x;
            double dy = q.y - y;

            return(new XYPT(x + (dx * cp) - (dy * sp),
                            y + (dx * sp) + (dy * cp)));
        }
Exemple #12
0
        public bool ContainsPoint(XYPT p)
        {
            if (m_points == null)
            {
                m_points = new List <XYPT>();
                return(false);
            }

            return(m_points.Contains(p));
        }
Exemple #13
0
        public double AngleTo02π(XYPT p)
        {
            XYPT q = p - this; double φ = Math.Atan2(q.y, q.x);

            if (φ < 0)
            {
                φ += Math.PI * 2;
            }
            return(φ);
        }
Exemple #14
0
        /// <summary>
        ///		Rotates p relative q.
        /// </summary>
        /// <param name="q">	The point being rotated.			</param>
        /// <param name="phi">	The angle of rotation (in radians).	</param>
        /// <returns></returns>
        public void rotateRel(XYPT q, double phi)
        {
            double cp = Math.Cos(phi);
            double sp = Math.Sin(phi);
            double dx = x - q.x;
            double dy = y - q.y;

            x = q.x + (dx * cp) - (dy * sp);
            y = q.y + (dx * sp) + (dy * cp);
        }
Exemple #15
0
        /// <summary>
        ///		Rotates q relative p.
        /// </summary>
        /// <param name="q">	The point being rotated.			</param>
        /// <param name="phi">	The angle of rotation (in radians).	</param>
        /// <returns></returns>
        public void rotate(ref XYPT q, double phi)
        {
            double cp = Math.Cos(phi);
            double sp = Math.Sin(phi);
            double dx = q.x - x;
            double dy = q.y - y;

            q.x = x + (dx * cp) - (dy * sp);
            q.y = y + (dx * sp) + (dy * cp);
        }
Exemple #16
0
 public void minimize(XYPT q)
 {
     if (q.x < this.x)
     {
         this.x = q.x;
     }
     if (q.y < this.y)
     {
         this.x = q.y;
     }
 }
Exemple #17
0
 public void maximize(XYPT q)
 {
     if (this.x < q.x)
     {
         this.x = q.x;
     }
     if (this.y < q.y)
     {
         this.x = q.y;
     }
 }
Exemple #18
0
        private XYPT GetCenter()
        {
            XYPT center = new XYPT();

            foreach (var point in m_points)
            {
                center.x += point.x;
                center.y += point.y;
            }
            center /= Count;
            return(center);
        }
Exemple #19
0
        public bool Pt2LinePt(XYPT pt1, XYPT pt2, XYPT pPerp, out XYPT pDrop, double epsilon = 0.001)
        {
            double dx = pt2.x - pt1.x;
            double dy = pt2.y - pt1.y;

            if ((dx == 0.0) && (dy == 0.0))
            {
                pDrop.x = pt1.x;
                pDrop.y = pt1.y;
                return(true);
            }

            if (Math.Abs(dy) <= Math.Abs(dx))
            {
                double m = dy / dx;             // Slope of line
                double b = pt1.y - m * pt1.x;   // Y-Intercept

                // Find the point on (x1,y1)-(x2,y2) that is closest to (x,y)

                double tmp = (pPerp.y - b) * m + pPerp.x;
                pDrop.x = tmp / (m * m + 1);
                pDrop.y = m * pDrop.x + b;
            }
            else
            {
                double m = dx / dy;             // Inverse slope of line
                double b = pt1.x - m * pt1.y;   // X-Intercept

                // Find the point on (x1,y1)-(x2,y2) that is closest to (x,y).

                double tmp = (pPerp.x - b) * m + pPerp.y;
                pDrop.y = tmp / (m * m + 1);
                pDrop.x = m * pDrop.y + b;
            }

            // x and y are the points on (x1,y1)-(x2,y2) such that
            // (x,y)-(xr,yr) is perpendicular to (x1,y1)-(x2,y2).

            bool b1 = (pt1.x <= pDrop.x + epsilon) && (pDrop.x <= pt2.x + epsilon);
            bool b2 = (pt2.x <= pDrop.x + epsilon) && (pDrop.x <= pt1.x + epsilon);
            bool b3 = (pt1.y <= pDrop.y + epsilon) && (pDrop.y <= pt2.y + epsilon);
            bool b4 = (pt2.y <= pDrop.y + epsilon) && (pDrop.y <= pt1.y + epsilon);

            if ((b1 || b2) && (b3 || b4))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #20
0
        public static XYPT sum(List <XYPT> listXYPT)
        {
            int  n = listXYPT.Count;
            XYPT s = new XYPT(0, 0);

            if (n <= 0)
            {
                return(s);
            }

            for (int i = 0; i < n; i++)
            {
                s += listXYPT[i];
            }
            return(s);
        }
Exemple #21
0
        public static XYPT sum(XYPT[] array)
        {
            int  n = array.GetLength(0);
            XYPT s = new XYPT(0, 0);

            if (n <= 0)
            {
                return(s);
            }

            for (int i = 0; i < n; i++)
            {
                s += array[i];
            }
            return(s);
        }
Exemple #22
0
        public static XYPT average(List <XYPT> listXYPT)
        {
            int  n   = listXYPT.Count;
            XYPT sum = new XYPT(0, 0);

            if (n <= 0)
            {
                return(sum);
            }

            for (int i = 0; i < n; i++)
            {
                sum += listXYPT[i];
            }
            return(sum / n);
        }
Exemple #23
0
        public static XYPT average(XYPT[] array)
        {
            int  n   = array.GetLength(0);
            XYPT sum = new XYPT(0, 0);

            if (n <= 0)
            {
                return(sum);
            }

            for (int i = 0; i < n; i++)
            {
                sum += array[i];
            }
            return(sum / n);
        }
Exemple #24
0
        /// <summary>
        /// checks if 2 points are the same
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override bool Equals(object obj)
        {
            if (obj == null || GetType() != obj.GetType())
            {
                return(false);
            }

            if (obj is XYPT)
            {
                XYPT xyPoint = (XYPT)obj;
                return(this.x == xyPoint.x &&
                       this.y == xyPoint.y);
            }
            else
            {
                return(false);
            }
        }
Exemple #25
0
        public bool PointOnLineSegment(XYPT pt1, XYPT pt2, XYPT pt, double epsilon = 0.001)
        {
            if (pt.XX - Math.Max(pt1.XX, pt2.XX) > epsilon ||
                Math.Min(pt1.XX, pt2.XX) - pt.XX > epsilon ||
                pt.YY - Math.Max(pt1.YY, pt2.YY) > epsilon ||
                Math.Min(pt1.YY, pt2.YY) - pt.YY > epsilon)
            {
                return(false);
            }

            if (Math.Abs(pt2.XX - pt1.XX) < epsilon)
            {
                return(Math.Abs(pt1.XX - pt.XX) < epsilon || Math.Abs(pt2.XX - pt.XX) < epsilon);
            }
            if (Math.Abs(pt2.YY - pt1.YY) < epsilon)
            {
                return(Math.Abs(pt1.YY - pt.YY) < epsilon || Math.Abs(pt2.YY - pt.YY) < epsilon);
            }

            double x = pt1.XX + (pt.YY - pt1.YY) * (pt2.XX - pt1.XX) / (pt2.YY - pt1.YY);
            double y = pt1.YY + (pt.XX - pt1.XX) * (pt2.YY - pt1.YY) / (pt2.XX - pt1.XX);

            return(Math.Abs(pt.XX - x) < epsilon || Math.Abs(pt.YY - y) < epsilon);
        }
Exemple #26
0
 public void swapWith(ref XYPT q)
 {
     XYPT t = this; this = q; q = t;
 }
Exemple #27
0
 public bool isNearlySameAs(XYPT q, double sepToler)
 {
     return(this.DistTo(q) <= sepToler);
 }
Exemple #28
0
 public void move(XYPT displacement)
 {
     x += displacement.x;
     y += displacement.y;
 }
Exemple #29
0
 public bool NearlyEquals(XYPT q, double sepToler)
 {
     return(this.DistTo(q) <= sepToler);
 }
Exemple #30
0
        /// <summary>
        ///		<para> Imagine a list of column vectors, each bearing a list of XY-points, essentially a 2d matrix.	</para>
        ///		<para> This utility averages points in the same row.												</para>
        /// </summary>
        /// <param name="list"> A list of lists of XYPTs </param>
        /// <returns></returns>
        public static      XYPT[] averageVectors(List <List <XYPT> > list)
        {
            /*	Example:
             *
             *	List[0]		List[1]		List[2]					XYPT[] Array
             *
             *	List[0][0]		[1][0]		[2][0]		==>		[0] = ( [0][0] + [1][0] + [2][0] ) / 3
             *		[0][1]		[1][1]		[2][1]		==>		[1] = ( [0][1] + [1][1] + [2][1] ) / 3
             *		[0][2]		[1][2]		[2][2]		==>		[2] = ( [0][2] + [1][2] + [2][2] ) / 3
             *		[0][3]		[1][3]		[2][3]		==>		[3] = ( [0][3] + [1][3] + [2][3] ) / 3
             *		[0][4]		[1][4]		[2][4]		==>		[4] = ( [0][4] + [1][4] + [2][4] ) / 3
             */
            int mVectors = list.Count;

            XYPT[] sum      = new XYPT[0];
            int    nRowsMax = 0;

            int[] n;

            if (mVectors <= 0)
            {
                return(sum);
            }

            for (int iRow = 0; iRow < mVectors; iRow++)
            {
                if (nRowsMax < list[iRow].Count)
                {
                    nRowsMax = list[iRow].Count;
                }
            }

            // Create the array of sums
            sum = new XYPT[nRowsMax];
            if (nRowsMax <= 0)
            {
                return(sum);
            }
            n = new int[nRowsMax];


            for (int iRow = 0; iRow < nRowsMax; iRow++)
            {
                sum[iRow] = XYPT.ZeroZero;                      // Zero the sums.
                for (int jCol = 0; jCol < mVectors; jCol++)
                {
                    int nXYPTs = list[jCol].Count;
                    if (1 <= nXYPTs && nXYPTs <= nRowsMax)
                    {
                        n[iRow]++;
                        sum[iRow] += list[jCol][iRow];
                    }
                }
            }
            for (int iRow = 0; iRow < nRowsMax; iRow++)
            {
                sum[iRow] /= n[iRow];
            }

            return(sum);
        }