Esempio n. 1
0
        public bool ContainsPosition(PolygonPoint p)
        {
            int n = this.Points.Count();
            if (n <= 0)
            {
                return false;
            }
            List<PolygonPoint> v = Points.ToList();
            v.Add(new PolygonPoint { Lat = v[0].Lat, Lon = v[0].Lon });

            int wn = 0;    // the winding number counter

            // loop through all edges of the polygon
            for (int i = 0; i < n; i++)
            {   // edge from V[i] to V[i+1]
                if (v[i].Lat <= p.Lat)
                {         // start y <= P.y
                    if (v[i + 1].Lat > p.Lat)      // an upward crossing
                        if (isLeft(v[i], v[i + 1], p) > 0)  // P left of edge
                            ++wn;            // have a valid up intersect
                }
                else
                {                       // start y > P.y (no test needed)
                    if (v[i + 1].Lat <= p.Lat)     // a downward crossing
                        if (isLeft(v[i], v[i + 1], p) < 0)  // P right of edge
                            --wn;            // have a valid down intersect
                }
            }

            return wn != 0;
        }
Esempio n. 2
0
        private static int isLeft(PolygonPoint P0, PolygonPoint P1, PolygonPoint P2)
        {
            double calc = ((P1.Lon - P0.Lon) * (P2.Lat - P0.Lat)
                           - (P2.Lon - P0.Lon) * (P1.Lat - P0.Lat));

            if (calc > 0)
            {
                return(1);
            }
            else if (calc < 0)
            {
                return(-1);
            }
            else
            {
                return(0);
            }
        }
Esempio n. 3
0
        public bool ContainsPosition(PolygonPoint p)
        {
            int n = this.Points.Count();

            if (n <= 0)
            {
                return(false);
            }
            List <PolygonPoint> v = Points.ToList();

            v.Add(new PolygonPoint {
                Lat = v[0].Lat, Lon = v[0].Lon
            });

            int wn = 0;    // the winding number counter

            // loop through all edges of the polygon
            for (int i = 0; i < n; i++)
            {                                              // edge from V[i] to V[i+1]
                if (v[i].Lat <= p.Lat)
                {                                          // start y <= P.y
                    if (v[i + 1].Lat > p.Lat)              // an upward crossing
                    {
                        if (isLeft(v[i], v[i + 1], p) > 0) // P left of edge
                        {
                            ++wn;                          // have a valid up intersect
                        }
                    }
                }
                else
                {                                          // start y > P.y (no test needed)
                    if (v[i + 1].Lat <= p.Lat)             // a downward crossing
                    {
                        if (isLeft(v[i], v[i + 1], p) < 0) // P right of edge
                        {
                            --wn;                          // have a valid down intersect
                        }
                    }
                }
            }

            return(wn != 0);
        }
Esempio n. 4
0
        public Polygon FromPointList(string name, string pointList)
        {
            pointList = pointList.TrimStart('\n', '\t');
            pointList = pointList.TrimEnd('\n', '\t');


            var points = pointList.Split(new String[] { " " }, StringSplitOptions.RemoveEmptyEntries);

            CultureInfo ci   = new CultureInfo("en-US");
            var         list = new List <PolygonPoint>(points.Length);

            for (int i = 0; i < points.Length; i++)
            {
                var p = points[i].Split(new String[] { "," }, StringSplitOptions.RemoveEmptyEntries);

                if (p.Length < 2 || p.Length > 3)
                {
                    throw new Exception("Invalid polygon // invalid point data");
                }

                PolygonPoint pp = new PolygonPoint();
                pp.Lon = double.Parse(p[0], ci);
                pp.Lat = double.Parse(p[1], ci);
                if (p.Length == 3)
                {
                    pp.Alt = double.Parse(p[2], ci);
                }


                list.Add(pp);
            }

            if (!list.First().Equals(list.Last()))
            {
                throw new Exception("Invalid polygon // First does not equal Last");
            }

            return(new Polygon()
            {
                Points = list, Name = name
            });
        }
Esempio n. 5
0
 public double DistanceTo(PolygonPoint p)
 {
     return(Math.Pow(this.Lat - p.Lat, 2) + Math.Pow(this.Lon - p.Lon, 2));
 }
Esempio n. 6
0
 private static int isLeft(PolygonPoint P0, PolygonPoint P1, PolygonPoint P2)
 {
     double calc = ((P1.Lon - P0.Lon) * (P2.Lat - P0.Lat)
             - (P2.Lon - P0.Lon) * (P1.Lat - P0.Lat));
     if (calc > 0)
         return 1;
     else if (calc < 0)
         return -1;
     else
         return 0;
 }
Esempio n. 7
0
 public double DistanceTo(PolygonPoint p)
 {
     return (Math.Pow(this.Lat - p.Lat, 2) + Math.Pow(this.Lon - p.Lon, 2));
 }
Esempio n. 8
0
        public Polygon FromPointList(string name, string pointList)
        {
            pointList = pointList.TrimStart('\n', '\t');
            pointList = pointList.TrimEnd('\n', '\t');

            
            var points = pointList.Split(new String[] { " " }, StringSplitOptions.RemoveEmptyEntries);
            
            CultureInfo ci = new CultureInfo("en-US");
            var list = new List<PolygonPoint>(points.Length);
            
            for (int i = 0; i < points.Length; i++) {

                var p = points[i].Split(new String[] { "," }, StringSplitOptions.RemoveEmptyEntries);

                if (p.Length < 2 || p.Length > 3) {
                    throw new Exception("Invalid polygon // invalid point data");
                }

                PolygonPoint pp = new PolygonPoint();
                pp.Lon = double.Parse(p[0], ci);
                pp.Lat = double.Parse(p[1], ci);
                if (p.Length == 3) {
                    pp.Alt = double.Parse(p[2], ci);
                }
                
                
                list.Add(pp);
               
            }
            
            if (!list.First().Equals(list.Last())) {
                throw new Exception("Invalid polygon // First does not equal Last");
            }

            return new Polygon() { Points = list, Name = name };
        }