Exemplo n.º 1
0
        public static Coordinate FindExtreme(List<Coordinate> points)
        {
            Coordinate p = new Coordinate(points[0]);
            for (int i = 1; i < points.Count; i++)
            {
                double x = points[i].X;
                double y = points[i].Y;
                if (x < p.X || (x == p.X && y < p.Y))
                {
                    p.X = x;
                    p.Y = y;
                }
            }

            return p;
        }
Exemplo n.º 2
0
        public static List<Coordinate> convexHull(List<Coordinate> points)
        {
            List<Coordinate> result = new List<Coordinate>();
            Coordinate extreme = Coordinate.FindExtreme(points);
            result.Add(new Coordinate(extreme));
            Coordinate p = new Coordinate(extreme);
            Coordinate q = new Coordinate(extreme);

            while (true)
            {
                Coordinate r = new Coordinate();
                for (int i = 0; i < points.Count; i++)
                {
                    if ((points[i].X == p.X) && (points[i].Y == p.Y))
                    {
                        continue;
                    }
                    r.X = points[i].X;
                    r.Y = points[i].Y;
                    int turn = Coordinate.OrientationOf(p, q, r);
                    double dist = (Coordinate.DistanceBetween(p, r)).CompareTo(Coordinate.DistanceBetween(p, q));
                    if (turn == -1 || turn == 0 && dist == 1)
                    {
                        q.X = r.X;
                        q.Y = r.Y;
                    }
                }
                if ((q.X == result[0].X) && (q.Y == result[0].Y))
                {
                    break;
                }
                result.Add(new Coordinate(q));
                p.X = q.X;
                p.Y = q.Y;
            }
            return result;
        }
Exemplo n.º 3
0
 public CoordinateDispInfo(Models.Coordinate codinate)
 {
     this.Coordinate = codinate;
 }
Exemplo n.º 4
0
 public double CrossProduct(Coordinate other)
 {
     return (this.X * other.Y - this.Y * other.X);
 }
Exemplo n.º 5
0
 public static int OrientationOf(Coordinate p, Coordinate q, Coordinate r)
 {
     return (((q.X - p.X) * (r.Y - p.Y)) - ((q.Y - p.Y) * (r.X - p.X))).CompareTo(0);
 }
Exemplo n.º 6
0
 public static double DistanceBetween(Coordinate p, Coordinate q)
 {
     double dx = q.X - p.X;
     double dy = q.Y - p.Y;
     return ((dx * dx) + (dy * dy));
 }
Exemplo n.º 7
0
 public Coordinate(Coordinate coordinate)
 {
     this.latitude = coordinate.latitude;
     this.longitude = coordinate.longitude;
     this.Colour = Color.Fuchsia;
 }
Exemplo n.º 8
0
 public Coordinate(Coordinate coordinate, Color colour)
 {
     this.latitude = coordinate.latitude;
     this.longitude = coordinate.longitude;
     this.Colour = colour;
 }
Exemplo n.º 9
0
 public Coordinate Subtract(Coordinate other)
 {
     return new Coordinate(this.Y - other.Y, this.X - other.X);
 }
Exemplo n.º 10
0
 /// <summary>
 /// Constructs AirplaneMove
 /// </summary>
 /// <param name="destination"></param>
 /// <param name="liftOff"></param>
 /// <param name="Flying"></param>
 public AirplaneMove(Coordinate destination, bool liftOff = false, bool Flying = false)
 {
     this.destination = destination;
     this.liftOff     = liftOff;
     this.Flying      = Flying;
 }