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; }
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; }
public CoordinateDispInfo(Models.Coordinate codinate) { this.Coordinate = codinate; }
public double CrossProduct(Coordinate other) { return (this.X * other.Y - this.Y * other.X); }
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); }
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)); }
public Coordinate(Coordinate coordinate) { this.latitude = coordinate.latitude; this.longitude = coordinate.longitude; this.Colour = Color.Fuchsia; }
public Coordinate(Coordinate coordinate, Color colour) { this.latitude = coordinate.latitude; this.longitude = coordinate.longitude; this.Colour = colour; }
public Coordinate Subtract(Coordinate other) { return new Coordinate(this.Y - other.Y, this.X - other.X); }
/// <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; }