public Map(string filename, Competition parentCompetition) : base() { Bitmap image = new Bitmap(filename); GpsPoint topLeftPoint; GpsPoint bottomRightPoint; double topLeftLatitude; double topLeftLongitude; double bottomRightLatitude; double bottomRightLongitude; string[] coordinatesFromPath = filename.Remove(filename.LastIndexOf(".")).Substring(filename.LastIndexOf(@"\") + 1).Split("_".ToCharArray()); foreach (string coordinate in coordinatesFromPath) { if (coordinate.Length != 6 || coordinate == null || coordinate == string.Empty) { throw (new FormatException("Coordinates in image name not in correct format!")); } } topLeftLongitude = Convert.ToDouble(coordinatesFromPath[0]); topLeftLatitude = Convert.ToDouble(coordinatesFromPath[1]); bottomRightLongitude = Convert.ToDouble(coordinatesFromPath[2]); bottomRightLatitude = Convert.ToDouble(coordinatesFromPath[3]); topLeftPoint = new GpsPoint(topLeftLatitude, topLeftLongitude, GpsPointFormatImport.Swiss); bottomRightPoint = new GpsPoint(bottomRightLatitude, bottomRightLongitude, GpsPointFormatImport.Swiss); this.image = image; this.mapName = filename; this.topLeftPoint = topLeftPoint; this.bottomRightPoint = bottomRightPoint; this.parcoursCollection = new ParcoursCollection(); this.parentCompetition = parentCompetition; }
/// <summary> /// Creates a Map Object. /// /// </summary> /// <param name="image">Bitmap Image of the Location, corresponding to the GPS-Points</param> /// <param name="topLeftPoint">GPS Point with the Coordinates of the upper Left Point on the Map Image</param> /// <param name="bottomRightPoint">GPS Point with the Coordinates of the lower Right Point on the Map Image</param> public Map(Bitmap image, GpsPoint topLeftPoint, GpsPoint bottomRightPoint, Competition parentCompetition) { this.Image = image; this.TopLeftPoint = topLeftPoint; this.BottomRightPoint = bottomRightPoint; this.parcoursCollection = new ParcoursCollection(); this.parentCompetition = parentCompetition; }
/// <summary> /// Returns true if the specified Gate was passed between the GPSPoints p1, p2 /// </summary> /// <param name="gate"></param> /// <param name="p1"></param> /// <param name="p2"></param> /// <returns></returns> public bool gatePassed(GpsPoint p1, GpsPoint p2) { double Ax = this.LeftPoint.Longitude; double Ay = this.LeftPoint.Latitude; double Bx = this.RightPoint.Longitude; double By = this.RightPoint.Latitude; double Cx = p1.Longitude; double Cy = p1.Latitude; double Dx = p2.Longitude; double Dy = p2.Latitude; //double* X, double* Y double distAB, theCos, theSin, newX, ABpos; // Fail if either line segment is zero-length. if (Ax == Bx && Ay == By || Cx == Dx && Cy == Dy) return false; // Fail if the segments share an end-point. if (Ax == Cx && Ay == Cy || Bx == Cx && By == Cy || Ax == Dx && Ay == Dy || Bx == Dx && By == Dy) { return false; } // (1) Translate the system so that point A is on the origin. Bx -= Ax; By -= Ay; Cx -= Ax; Cy -= Ay; Dx -= Ax; Dy -= Ay; // Discover the length of segment A-B. distAB = Math.Sqrt(Bx * Bx + By * By); // (2) Rotate the system so that point B is on the positive X axis. theCos = Bx / distAB; theSin = By / distAB; newX = Cx * theCos + Cy * theSin; Cy = Cy * theCos - Cx * theSin; Cx = newX; newX = Dx * theCos + Dy * theSin; Dy = Dy * theCos - Dx * theSin; Dx = newX; // Fail if segment C-D doesn't cross line A-B. if (Cy < 0.0 && Dy < 0.0 || Cy >= 0.0 && Dy >= 0.0) return false; // (3) Discover the position of the intersection point along line A-B. ABpos = Dx + (Cx - Dx) * Dy / (Dy - Cy); // Fail if segment C-D crosses line A-B outside of segment A-B. if (ABpos < 0.0 || ABpos > distAB) return false; else { return true; } }
public Gate(GpsPoint leftPoint, GpsPoint rightPoint) : base() { this.LeftPoint = leftPoint; this.RightPoint = rightPoint; }
public bool MissedGate( GpsPoint p1, GpsPoint p2) { Gate extendedGate = new Gate(); double m = (p1.Latitude - p2.Latitude) / (p1.Longitude - p2.Longitude); extendedGate.LeftPoint.Longitude += 10000; extendedGate.LeftPoint.Latitude += 10000* m; extendedGate.RightPoint.Longitude += 10000; extendedGate.rightPoint.Latitude += 10000 * m; return gatePassed(p1, p2); }
public bool Contains(GpsPoint item) { return items.Contains(item); }
public void Add(GpsPoint item) { items.Add(item); }
public void Remove(GpsPoint item) { items.Remove(item); }
public void AddGpsPoint(GpsPoint gpsPoint) { gpsPoints.Add(gpsPoint); }
public Gate getExtendedGate(Gate gate) { double k = 200; //distance to middle point GpsPoint m = new GpsPoint((gate.LeftPoint.Latitude + gate.RightPoint.Latitude) / 2, (gate.LeftPoint.Longitude + gate.RightPoint.Longitude) / 2, GpsPointFormatImport.WGS84); double alpha = Math.Atan((gate.LeftPoint.Latitude - gate.RightPoint.Latitude) / (gate.LeftPoint.Longitude + gate.RightPoint.Longitude)); GpsPoint p1 = new GpsPoint(m.Latitude - (k * Math.Cos(alpha - (Math.PI / 2))), m.Longitude - (k * Math.Sin(alpha - (Math.PI / 2))), GpsPointFormatImport.WGS84); GpsPoint p2 = new GpsPoint(m.Latitude + (k * Math.Cos((Math.PI / 2) - alpha)), m.Longitude + (k * Math.Sin((Math.PI / 2) - alpha)), GpsPointFormatImport.WGS84); return new Gate(p1, p2); }