/// <summary> /// Returns the intersection of both lines. /// </summary> /// <param name="Line1">A line.</param> /// <param name="Line2">A line.</param> /// <param name="InfiniteLines">Whether the lines should be treated as infinite or not.</param> public GeoCoordinate Intersection(GeoLine Line2, Boolean InfiniteLines = false, Boolean ExcludeEdges = false) { GeoCoordinate Intersection; IntersectsWith(Line2, out Intersection, InfiniteLines, ExcludeEdges); return(Intersection); }
/// <summary> /// Checks if the given first pixel is within the circle /// defined by the remaining three edge pixels. /// </summary> /// <param name="Pixel">The pixel to be checked.</param> /// <param name="EdgePixel1">The first edge pixel defining a circle.</param> /// <param name="EdgePixel2">The second edge pixel defining a circle.</param> /// <param name="EdgePixel3">The third edge pixel defining a circle.</param> public static Boolean IsInCircle(GeoCoordinate Pixel, GeoCoordinate EdgePixel1, GeoCoordinate EdgePixel2, GeoCoordinate EdgePixel3) { #region Initial Checks if (Pixel == null) { throw new ArgumentNullException("The given first pixel must not be null!"); } if (EdgePixel1 == null) { throw new ArgumentNullException("The given first edgepixel must not be null!"); } if (EdgePixel2 == null) { throw new ArgumentNullException("The given second edgepixel must not be null!"); } if (EdgePixel3 == null) { throw new ArgumentNullException("The given third edgepixel must not be null!"); } #endregion #region Math Checks if (EdgePixel1.Equals(EdgePixel2) || EdgePixel1.Equals(EdgePixel3) || EdgePixel2.Equals(EdgePixel3)) { throw new ArgumentException("All distances between the pixels must be larger than zero!"); } if (EdgePixel1.Longitude.Value.Equals(EdgePixel2.Longitude.Value) && EdgePixel2.Longitude.Value.Equals(EdgePixel3.Longitude.Value)) { throw new ArgumentException("All three pixels must not be on a single line!"); } if (EdgePixel1.Latitude.Value.Equals(EdgePixel2.Latitude.Value) && EdgePixel2.Latitude.Value.Equals(EdgePixel3.Latitude.Value)) { throw new ArgumentException("All three pixels must not be on a single line!"); } #endregion var _Line12 = new GeoLine(EdgePixel1, EdgePixel2); var _Line23 = new GeoLine(EdgePixel2, EdgePixel3); var Center = new GeoLine(_Line12.Center, _Line12.Normale). Intersection( new GeoLine(_Line23.Center, _Line23.Normale)); return(Center.DistanceTo(Pixel) <= Center.DistanceTo(EdgePixel1)); }
/// <summary> /// Creates a circumcircle of type T based on three pixels. /// </summary> /// <param name="Pixel1">The first pixel of the triangle.</param> /// <param name="Pixel2">The second pixel of the triangle.</param> /// <param name="Pixel3">The third pixel of the triangle.</param> public GeoCircle(GeoCoordinate Pixel1, GeoCoordinate Pixel2, GeoCoordinate Pixel3) { #region Initial Checks if (Pixel1 == null) { throw new ArgumentNullException("The given first pixel must not be null!"); } if (Pixel2 == null) { throw new ArgumentNullException("The given second pixel must not be null!"); } if (Pixel3 == null) { throw new ArgumentNullException("The given third pixel must not be null!"); } #endregion #region Math Checks if (Pixel1.Equals(Pixel2) || Pixel1.Equals(Pixel3) || Pixel2.Equals(Pixel3)) { throw new ArgumentException("All distances between the pixels must be larger than zero!"); } //if (Pixel1.Longitude.Value.Equals(Pixel2.Longitude.Value) && // Pixel2.Longitude.Value.Equals(Pixel3.Longitude.Value)) // throw new ArgumentException("All three pixels must not be on a single line!"); //if (Pixel1.Latitude.Value.Equals(Pixel2.Latitude.Value) && // Pixel2.Latitude.Value.Equals(Pixel3.Latitude.Value)) // throw new ArgumentException("All three pixels must not be on a single line!"); #endregion var _Line12 = new GeoLine(Pixel1, Pixel2); var _Line23 = new GeoLine(Pixel2, Pixel3); this.Center = new GeoLine(_Line12.Center, _Line12.Normale). Intersection( new GeoLine(_Line23.Center, _Line23.Normale)); this.Radius = (Center != null) ? Center.DistanceTo(Pixel1) : 0; }
/// <summary> /// Compares two lines for equality. /// </summary> /// <param name="ILine">A line to compare with.</param> /// <returns>True if both match; False otherwise.</returns> public Boolean Equals(GeoLine ILine) { if ((Object)ILine == null) { return(false); } // Normal direction return((this.P1.Longitude.Value.Equals(ILine.P1.Longitude.Value) && this.P1.Latitude.Value.Equals(ILine.P1.Latitude.Value) && this.P2.Longitude.Value.Equals(ILine.P2.Longitude.Value) && this.P2.Latitude.Value.Equals(ILine.P2.Latitude.Value)) || // Opposite direction (this.P1.Longitude.Value.Equals(ILine.P2.Longitude.Value) && this.P1.Latitude.Value.Equals(ILine.P2.Latitude.Value) && this.P2.Longitude.Value.Equals(ILine.P1.Longitude) && this.P2.Latitude.Value.Equals(ILine.P1.Latitude))); }
/// <summary> /// Checks if the given lines intersect. /// </summary> /// <param name="Line1">A line.</param> /// <param name="Line2">A line.</param> /// <param name="InfiniteLines">Whether the lines should be treated as infinite or not.</param> /// <returns>True if the lines intersect; False otherwise.</returns> public Boolean IntersectsWith(GeoLine Line2, Boolean InfiniteLines = false, Boolean ExcludeEdges = false) { GeoCoordinate Intersection; return IntersectsWith(Line2, out Intersection, InfiniteLines, ExcludeEdges); }
/// <summary> /// Checks if and where the given lines intersect. /// </summary> /// <param name="Line">A line.</param> /// <param name="IntersectionGeoCoordinate">The intersection of both lines.</param> /// <param name="InfiniteLines">Whether the lines should be treated as infinite or not.</param> /// <returns>True if the lines intersect; False otherwise.</returns> public Boolean IntersectsWith(GeoLine Line, out GeoCoordinate IntersectionGeoCoordinate, Boolean InfiniteLines = false, Boolean ExcludeEdges = false) { #region Initial Checks if (Line == null) { IntersectionGeoCoordinate = default(GeoCoordinate); return false; } #endregion // Assume both lines are infinite in order to get their intersection... #region This line is just a pixel if (this.IsJustAPixel()) { if (Line.Contains(P1)) { IntersectionGeoCoordinate = P1; return true; } IntersectionGeoCoordinate = default(GeoCoordinate); return false; } #endregion #region The given line is just a pixel else if (Line.IsJustAPixel()) { if (this.Contains(Line.P1)) { IntersectionGeoCoordinate = Line.P1; return true; } IntersectionGeoCoordinate = default(GeoCoordinate); return false; } #endregion #region Both lines are parallel else if (this.Gradient == Line.Gradient) { IntersectionGeoCoordinate = default(GeoCoordinate); return false; } #endregion #region Both lines are antiparallel else if (this.Gradient == -1*Line.Gradient) { IntersectionGeoCoordinate = default(GeoCoordinate); return false; } #endregion #region This line is parallel to the y-axis else if (Double.IsInfinity(this.Gradient)) { IntersectionGeoCoordinate = new GeoCoordinate(new Latitude (Line.Gradient * this.P1.Longitude.Value + Line.YIntercept), this.P1.Longitude); } #endregion #region The given line is parallel to the y-axis else if (Double.IsInfinity(Line.Gradient)) { IntersectionGeoCoordinate = new GeoCoordinate(new Latitude(this.Gradient * Line.P1.Longitude.Value + this.YIntercept), Line.P1.Longitude); } #endregion #region There is a real intersection else { //IntersectionGeoCoordinate = null; //// this Line //var A1 = this.P2.Latitude. Value - this.P1.Latitude. Value; //var B1 = this.P2.Longitude.Value - this.P1.Longitude.Value; //var C1 = A1 * this.P1.Longitude.Value + B1 * this.P1.Latitude.Value; //// Line2 //var A2 = Line.P2.Latitude. Value - Line.P1.Latitude. Value; //var B2 = Line.P2.Longitude.Value - Line.P1.Longitude.Value; //var C2 = A2 * Line.P1.Longitude.Value + B2 * Line.P1.Latitude.Value; //var det = A1 * B2 - A2 * B1; //if (det == 0) //{ // //parallel lines //} //else //{ // var x = (B2 * C1 - B1 * C2) / det; // var y = (A1 * C2 - A2 * C1) / det; // IntersectionGeoCoordinate = new GeoCoordinate(new Latitude (y), // new Longitude(x)); //} IntersectionGeoCoordinate = new GeoCoordinate(new Latitude ((this.YIntercept * Line.Gradient - Line.YIntercept * this.Gradient) / (Line.Gradient - this.Gradient)), new Longitude((Line.YIntercept - this.YIntercept) / (this.Gradient - Line.Gradient))); } #endregion if (InfiniteLines) return true; else if (!ExcludeEdges) return this.Contains(IntersectionGeoCoordinate); else { if (this.Contains(IntersectionGeoCoordinate)) { if (IntersectionGeoCoordinate.Equals(P1) || IntersectionGeoCoordinate.Equals(P2) || IntersectionGeoCoordinate.Equals(Line.P1) || IntersectionGeoCoordinate.Equals(Line.P2)) return false; return true; } return false; } }
/// <summary> /// Compares two lines for equality. /// </summary> /// <param name="ILine">A line to compare with.</param> /// <returns>True if both match; False otherwise.</returns> public Boolean Equals(GeoLine ILine) { if ((Object) ILine == null) return false; // Normal direction return (this.P1.Longitude.Value.Equals(ILine.P1.Longitude.Value) && this.P1.Latitude .Value.Equals(ILine.P1.Latitude.Value) && this.P2.Longitude.Value.Equals(ILine.P2.Longitude.Value) && this.P2.Latitude .Value.Equals(ILine.P2.Latitude.Value)) || // Opposite direction (this.P1.Longitude.Value.Equals(ILine.P2.Longitude.Value) && this.P1.Latitude .Value.Equals(ILine.P2.Latitude.Value) && this.P2.Longitude.Value.Equals(ILine.P1.Longitude) && this.P2.Latitude .Value.Equals(ILine.P1.Latitude)); }
/// <summary> /// Creates a circumcircle of type T based on three pixels. /// </summary> /// <param name="Pixel1">The first pixel of the triangle.</param> /// <param name="Pixel2">The second pixel of the triangle.</param> /// <param name="Pixel3">The third pixel of the triangle.</param> public GeoCircle(GeoCoordinate Pixel1, GeoCoordinate Pixel2, GeoCoordinate Pixel3) { #region Initial Checks if (Pixel1 == null) throw new ArgumentNullException("The given first pixel must not be null!"); if (Pixel2 == null) throw new ArgumentNullException("The given second pixel must not be null!"); if (Pixel3 == null) throw new ArgumentNullException("The given third pixel must not be null!"); #endregion #region Math Checks if (Pixel1.Equals(Pixel2) || Pixel1.Equals(Pixel3) || Pixel2.Equals(Pixel3)) throw new ArgumentException("All distances between the pixels must be larger than zero!"); //if (Pixel1.Longitude.Value.Equals(Pixel2.Longitude.Value) && // Pixel2.Longitude.Value.Equals(Pixel3.Longitude.Value)) // throw new ArgumentException("All three pixels must not be on a single line!"); //if (Pixel1.Latitude.Value.Equals(Pixel2.Latitude.Value) && // Pixel2.Latitude.Value.Equals(Pixel3.Latitude.Value)) // throw new ArgumentException("All three pixels must not be on a single line!"); #endregion var _Line12 = new GeoLine(Pixel1, Pixel2); var _Line23 = new GeoLine(Pixel2, Pixel3); this.Center = new GeoLine(_Line12.Center, _Line12.Normale). Intersection( new GeoLine(_Line23.Center, _Line23.Normale)); this.Radius = (Center != null) ? Center.DistanceTo(Pixel1) : 0; }
/// <summary> /// Checks if the given first pixel is within the circle /// defined by the remaining three edge pixels. /// </summary> /// <param name="Pixel">The pixel to be checked.</param> /// <param name="EdgePixel1">The first edge pixel defining a circle.</param> /// <param name="EdgePixel2">The second edge pixel defining a circle.</param> /// <param name="EdgePixel3">The third edge pixel defining a circle.</param> public static Boolean IsInCircle(GeoCoordinate Pixel, GeoCoordinate EdgePixel1, GeoCoordinate EdgePixel2, GeoCoordinate EdgePixel3) { #region Initial Checks if (Pixel == null) throw new ArgumentNullException("The given first pixel must not be null!"); if (EdgePixel1 == null) throw new ArgumentNullException("The given first edgepixel must not be null!"); if (EdgePixel2 == null) throw new ArgumentNullException("The given second edgepixel must not be null!"); if (EdgePixel3 == null) throw new ArgumentNullException("The given third edgepixel must not be null!"); #endregion #region Math Checks if (EdgePixel1.Equals(EdgePixel2) || EdgePixel1.Equals(EdgePixel3) || EdgePixel2.Equals(EdgePixel3)) throw new ArgumentException("All distances between the pixels must be larger than zero!"); if (EdgePixel1.Longitude.Value.Equals(EdgePixel2.Longitude.Value) && EdgePixel2.Longitude.Value.Equals(EdgePixel3.Longitude.Value)) throw new ArgumentException("All three pixels must not be on a single line!"); if (EdgePixel1.Latitude.Value.Equals(EdgePixel2.Latitude.Value) && EdgePixel2.Latitude.Value.Equals(EdgePixel3.Latitude.Value)) throw new ArgumentException("All three pixels must not be on a single line!"); #endregion var _Line12 = new GeoLine(EdgePixel1, EdgePixel2); var _Line23 = new GeoLine(EdgePixel2, EdgePixel3); var Center = new GeoLine(_Line12.Center, _Line12.Normale). Intersection( new GeoLine(_Line23.Center, _Line23.Normale)); return Center.DistanceTo(Pixel) <= Center.DistanceTo(EdgePixel1); }
/// <summary> /// Calculate a delaunay triangulation for the given enumeration of pixels. /// </summary> /// <typeparam name="T">The type of the pixels.</typeparam> /// <param name="VoronoiFeatures">An enumeration of pixels of type T.</param> /// <returns>An enumeration of triangles of type T.</returns> public static IEnumerable<TriCircle> DelaunayTriangulation(this IEnumerable<VoronoiFeature> VoronoiFeatures) { #region Initial Checks var _VoronoiFeatures = VoronoiFeatures.ToList(); var _NumberOfFeatures = _VoronoiFeatures.Count; //if (_NumberOfFeatures < 3) // throw new ArgumentException("Need at least three pixels for triangulation!"); var TriCircles = new List<TriCircle>(); #endregion #region Set up the first triangle var j = 0; VoronoiFeature[] tri1; TriCircle triangle = null; do { tri1 = _VoronoiFeatures.Skip(j++).Take(3).ToArray(); triangle = new TriCircle(new GeoTriangle(tri1[0].GeoCoordinate, tri1[1].GeoCoordinate, tri1[2].GeoCoordinate)); } while (triangle.Circle.Radius == 0); TriCircles.Add(triangle); _VoronoiFeatures = _VoronoiFeatures.Where(vf => !tri1.Contains(vf)).ToList(); #endregion #region Include each point one at a time into the existing mesh for (int i = 0; i < _VoronoiFeatures.Count; i++) { var Found = false; #region The new voronoi feature lies inside an existing triangle var TriCircleList = TriCircles.Where(TriCircle => TriCircle.Deleted == false). OrderBy(TriCircle => TriCircle.Circle.Radius).ToArray(); foreach (var TriCircle in TriCircleList) { if (TriCircle.Triangle.Contains(_VoronoiFeatures[i].GeoCoordinate)) { var Edges = new List<GeoLine>(); Edges.Add(new GeoLine(TriCircle.Triangle.P1, TriCircle.Triangle.P2)); Edges.Add(new GeoLine(TriCircle.Triangle.P2, TriCircle.Triangle.P3)); Edges.Add(new GeoLine(TriCircle.Triangle.P3, TriCircle.Triangle.P1)); // Add three new triangles for the current point foreach (var _Edge in Edges) TriCircles.Add(new TriCircle(new GeoTriangle(_Edge.P1, _Edge.P2, _VoronoiFeatures[i].GeoCoordinate))); TriCircle.Deleted = true; Found = true; break; } } #endregion #region An external feature if (!Found) { var PointList1 = (TriCircles.Select(TriCircle => new { point = TriCircle.Triangle.P1, distance = TriCircle.Triangle.P1.DistanceTo(_VoronoiFeatures[i].GeoCoordinate) }). Union( TriCircles.Select(TriCircle => new { point = TriCircle.Triangle.P2, distance = TriCircle.Triangle.P2.DistanceTo(_VoronoiFeatures[i].GeoCoordinate) })). Union( TriCircles.Select(TriCircle => new { point = TriCircle.Triangle.P3, distance = TriCircle.Triangle.P3.DistanceTo(_VoronoiFeatures[i].GeoCoordinate) }))). OrderBy(agg => agg.distance).ToArray(); var PointList2 = PointList1. Where(v => { var newLine = new GeoLine(_VoronoiFeatures[i].GeoCoordinate, v.point); foreach (var edges in TriCircles.Select(v2 => v2.Triangle.Borders)) { foreach (var edge in edges) { if (edge.IntersectsWith(newLine, false, true)) { return false; } } } return true; }). ToArray(); TriCircles.Add(new TriCircle(new GeoTriangle(PointList2[0].point, PointList2[1].point, _VoronoiFeatures[i].GeoCoordinate))); } #endregion } #endregion return TriCircles.Where(tc => tc.Deleted == false);//.Select(tc => tc.Triangle); }
/// <summary> /// Checks if and where the given lines intersect. /// </summary> /// <param name="Line">A line.</param> /// <param name="IntersectionGeoCoordinate">The intersection of both lines.</param> /// <param name="InfiniteLines">Whether the lines should be treated as infinite or not.</param> /// <returns>True if the lines intersect; False otherwise.</returns> public Boolean IntersectsWith(GeoLine Line, out GeoCoordinate IntersectionGeoCoordinate, Boolean InfiniteLines = false, Boolean ExcludeEdges = false) { #region Initial Checks if (Line == null) { IntersectionGeoCoordinate = default(GeoCoordinate); return(false); } #endregion // Assume both lines are infinite in order to get their intersection... #region This line is just a pixel if (this.IsJustAPixel()) { if (Line.Contains(P1)) { IntersectionGeoCoordinate = P1; return(true); } IntersectionGeoCoordinate = default(GeoCoordinate); return(false); } #endregion #region The given line is just a pixel else if (Line.IsJustAPixel()) { if (this.Contains(Line.P1)) { IntersectionGeoCoordinate = Line.P1; return(true); } IntersectionGeoCoordinate = default(GeoCoordinate); return(false); } #endregion #region Both lines are parallel else if (this.Gradient == Line.Gradient) { IntersectionGeoCoordinate = default(GeoCoordinate); return(false); } #endregion #region Both lines are antiparallel else if (this.Gradient == -1 * Line.Gradient) { IntersectionGeoCoordinate = default(GeoCoordinate); return(false); } #endregion #region This line is parallel to the y-axis else if (Double.IsInfinity(Gradient)) { IntersectionGeoCoordinate = new GeoCoordinate( Latitude.Parse(Line.Gradient * P1.Longitude.Value + Line.YIntercept), P1.Longitude ); } #endregion #region The given line is parallel to the y-axis else if (Double.IsInfinity(Line.Gradient)) { IntersectionGeoCoordinate = new GeoCoordinate( Latitude.Parse(Gradient * Line.P1.Longitude.Value + YIntercept), Line.P1.Longitude ); } #endregion #region There is a real intersection else { //IntersectionGeoCoordinate = null; //// this Line //var A1 = this.P2.Latitude. Value - this.P1.Latitude. Value; //var B1 = this.P2.Longitude.Value - this.P1.Longitude.Value; //var C1 = A1 * this.P1.Longitude.Value + B1 * this.P1.Latitude.Value; //// Line2 //var A2 = Line.P2.Latitude. Value - Line.P1.Latitude. Value; //var B2 = Line.P2.Longitude.Value - Line.P1.Longitude.Value; //var C2 = A2 * Line.P1.Longitude.Value + B2 * Line.P1.Latitude.Value; //var det = A1 * B2 - A2 * B1; //if (det == 0) //{ // //parallel lines //} //else //{ // var x = (B2 * C1 - B1 * C2) / det; // var y = (A1 * C2 - A2 * C1) / det; // IntersectionGeoCoordinate = new GeoCoordinate(new Latitude (y), // new Longitude(x)); //} IntersectionGeoCoordinate = new GeoCoordinate( Latitude.Parse((this.YIntercept * Line.Gradient - Line.YIntercept * this.Gradient) / (Line.Gradient - this.Gradient)), Longitude.Parse((Line.YIntercept - this.YIntercept) / (this.Gradient - Line.Gradient)) ); } #endregion if (InfiniteLines) { return(true); } else if (!ExcludeEdges) { return(this.Contains(IntersectionGeoCoordinate)); } else { if (this.Contains(IntersectionGeoCoordinate)) { if (IntersectionGeoCoordinate.Equals(P1) || IntersectionGeoCoordinate.Equals(P2) || IntersectionGeoCoordinate.Equals(Line.P1) || IntersectionGeoCoordinate.Equals(Line.P2)) { return(false); } return(true); } return(false); } }
/// <summary> /// Calculate a delaunay triangulation for the given enumeration of pixels. /// </summary> /// <typeparam name="T">The type of the pixels.</typeparam> /// <param name="VoronoiFeatures">An enumeration of pixels of type T.</param> /// <returns>An enumeration of triangles of type T.</returns> public static IEnumerable <TriCircle> DelaunayTriangulation(this IEnumerable <VoronoiFeature> VoronoiFeatures) { #region Initial Checks var _VoronoiFeatures = VoronoiFeatures.ToList(); var _NumberOfFeatures = _VoronoiFeatures.Count; //if (_NumberOfFeatures < 3) // throw new ArgumentException("Need at least three pixels for triangulation!"); var TriCircles = new List <TriCircle>(); #endregion #region Set up the first triangle var j = 0; VoronoiFeature[] tri1; TriCircle triangle = null; do { tri1 = _VoronoiFeatures.Skip(j++).Take(3).ToArray(); triangle = new TriCircle(new GeoTriangle(tri1[0].GeoCoordinate, tri1[1].GeoCoordinate, tri1[2].GeoCoordinate)); }while (triangle.Circle.Radius == 0); TriCircles.Add(triangle); _VoronoiFeatures = _VoronoiFeatures.Where(vf => !tri1.Contains(vf)).ToList(); #endregion #region Include each point one at a time into the existing mesh for (int i = 0; i < _VoronoiFeatures.Count; i++) { var Found = false; #region The new voronoi feature lies inside an existing triangle var TriCircleList = TriCircles.Where(TriCircle => TriCircle.Deleted == false). OrderBy(TriCircle => TriCircle.Circle.Radius).ToArray(); foreach (var TriCircle in TriCircleList) { if (TriCircle.Triangle.Contains(_VoronoiFeatures[i].GeoCoordinate)) { var Edges = new List <GeoLine>(); Edges.Add(new GeoLine(TriCircle.Triangle.P1, TriCircle.Triangle.P2)); Edges.Add(new GeoLine(TriCircle.Triangle.P2, TriCircle.Triangle.P3)); Edges.Add(new GeoLine(TriCircle.Triangle.P3, TriCircle.Triangle.P1)); // Add three new triangles for the current point foreach (var _Edge in Edges) { TriCircles.Add(new TriCircle(new GeoTriangle(_Edge.P1, _Edge.P2, _VoronoiFeatures[i].GeoCoordinate))); } TriCircle.Deleted = true; Found = true; break; } } #endregion #region An external feature if (!Found) { var PointList1 = (TriCircles.Select(TriCircle => new { point = TriCircle.Triangle.P1, distance = TriCircle.Triangle.P1.DistanceTo(_VoronoiFeatures[i].GeoCoordinate) }). Union( TriCircles.Select(TriCircle => new { point = TriCircle.Triangle.P2, distance = TriCircle.Triangle.P2.DistanceTo(_VoronoiFeatures[i].GeoCoordinate) })). Union( TriCircles.Select(TriCircle => new { point = TriCircle.Triangle.P3, distance = TriCircle.Triangle.P3.DistanceTo(_VoronoiFeatures[i].GeoCoordinate) }))). OrderBy(agg => agg.distance).ToArray(); var PointList2 = PointList1. Where(v => { var newLine = new GeoLine(_VoronoiFeatures[i].GeoCoordinate, v.point); foreach (var edges in TriCircles.Select(v2 => v2.Triangle.Borders)) { foreach (var edge in edges) { if (edge.IntersectsWith(newLine, false, true)) { return(false); } } } return(true); }). ToArray(); TriCircles.Add(new TriCircle(new GeoTriangle(PointList2[0].point, PointList2[1].point, _VoronoiFeatures[i].GeoCoordinate))); } #endregion } #endregion return(TriCircles.Where(tc => tc.Deleted == false));//.Select(tc => tc.Triangle); }
private void DrawLine(GeoLine Line, Brush Stroke, Double StrokeThickness) { DrawLine(Line.P1, Line.P2, Stroke, StrokeThickness); }
private void Calc() { if (VoronoiFeatures.Count > 2) { #region Draw Delaunay if (DelaunayTriangleList == null) { DelaunayTriangleList = VoronoiFeatures.DelaunayTriangulation().ToList(); } if (DelaunayTriangleList != null) { foreach (var DelaunayTriangle in DelaunayTriangleList) { var P1OnScreen = GeoCalculations.GeoCoordinate2ScreenXY(DelaunayTriangle.Triangle.P1, this.MapControl.ZoomLevel); var P2OnScreen = GeoCalculations.GeoCoordinate2ScreenXY(DelaunayTriangle.Triangle.P2, this.MapControl.ZoomLevel); var P3OnScreen = GeoCalculations.GeoCoordinate2ScreenXY(DelaunayTriangle.Triangle.P3, this.MapControl.ZoomLevel); ////DrawLine(P1OnScreen, P2OnScreen, Brushes.Blue, 1.0); ////DrawLine(P2OnScreen, P3OnScreen, Brushes.Blue, 1.0); ////DrawLine(P3OnScreen, P1OnScreen, Brushes.Blue, 1.0); //var GeoCircle = new GeoCircle(_Triangle.P1, _Triangle.P2, _Triangle.P3); var ScreenCircle = new Circle <Double>(new Pixel <Double>(P1OnScreen.X + this.MapControl.ScreenOffset.X, P1OnScreen.Y + this.MapControl.ScreenOffset.Y), new Pixel <Double>(P2OnScreen.X + this.MapControl.ScreenOffset.X, P2OnScreen.Y + this.MapControl.ScreenOffset.Y), new Pixel <Double>(P3OnScreen.X + this.MapControl.ScreenOffset.X, P3OnScreen.Y + this.MapControl.ScreenOffset.Y)); //var r1 = ScreenCircle.Center.DistanceTo(P1OnScreen.X + this.MapControl.ScreenOffset.X, P1OnScreen.Y + this.MapControl.ScreenOffset.Y); //var r2 = ScreenCircle.Center.DistanceTo(P2OnScreen.X + this.MapControl.ScreenOffset.X, P2OnScreen.Y + this.MapControl.ScreenOffset.Y); //var r3 = ScreenCircle.Center.DistanceTo(P3OnScreen.X + this.MapControl.ScreenOffset.X, P3OnScreen.Y + this.MapControl.ScreenOffset.Y); //var CenterOnScreen = GeoCalculations.GeoCoordinate2ScreenXY(GeoCircle.Center, this.MapControl.ZoomLevel); #region DrawCircumCircles if (DrawCircumCircles) { var CircumCircle = new Ellipse() { Width = ScreenCircle.Diameter, Height = ScreenCircle.Diameter, Stroke = Brushes.DarkGreen, StrokeThickness = 1.0 }; this.Children.Add(CircumCircle); //Canvas.SetLeft(CircumCircle, CenterOnScreen.X + this.MapControl.ScreenOffset.X); //Canvas.SetTop (CircumCircle, CenterOnScreen.Y + this.MapControl.ScreenOffset.Y); Canvas.SetLeft(CircumCircle, ScreenCircle.X - ScreenCircle.Radius); // + this.MapControl.ScreenOffset.X); Canvas.SetTop(CircumCircle, ScreenCircle.Y - ScreenCircle.Radius); // + this.MapControl.ScreenOffset.Y); } #endregion } } foreach (var tr1 in DelaunayTriangleList) { tr1.Neighbors.Clear(); } HashSet <GeoCoordinate> tr1_h, tr2_h; IEnumerable <GeoCoordinate> Intersection; foreach (var tr1 in DelaunayTriangleList) { foreach (var tr2 in DelaunayTriangleList) { tr1_h = new HashSet <GeoCoordinate>(); tr1_h.Add(tr1.Triangle.P1); tr1_h.Add(tr1.Triangle.P2); tr1_h.Add(tr1.Triangle.P3); tr2_h = new HashSet <GeoCoordinate>(); tr2_h.Add(tr2.Triangle.P1); tr2_h.Add(tr2.Triangle.P2); tr2_h.Add(tr2.Triangle.P3); Intersection = tr1_h.Intersect(tr2_h); if (Intersection.Count() == 2) { tr1.Neighbors.Add(tr2); tr2.Neighbors.Add(tr1); foreach (var bo in tr1.Triangle.Borders) { if (Intersection.Contains(bo.P1) && Intersection.Contains(bo.P2)) { bo.Tags.Add("shared"); } } foreach (var bo in tr2.Triangle.Borders) { if (Intersection.Contains(bo.P1) && Intersection.Contains(bo.P2)) { bo.Tags.Add("shared"); } } } } } var aaa = DelaunayTriangleList.SelectMany(v => v.Triangle.Borders).Select(v => v.Tags); foreach (var DelaunayTriangle in DelaunayTriangleList) { foreach (var Edge in DelaunayTriangle.Triangle.Borders) { DrawLine(GeoCalculations.GeoCoordinate2ScreenXY(Edge.P1, this.MapControl.ZoomLevel), GeoCalculations.GeoCoordinate2ScreenXY(Edge.P2, this.MapControl.ZoomLevel), (Edge.Tags.Contains("shared")) ? Brushes.LightBlue : Brushes.Blue, 1.0); } } foreach (var tr1 in DelaunayTriangleList)//.Skip(2).Take(1)) { var Borders = tr1.Triangle.Borders.ToList(); var Center = new GeoLine(Borders[0].Center, Borders[0].Normale). Intersection(new GeoLine(Borders[1].Center, Borders[1].Normale)); var Vector1 = Borders[0].Vector; var Vector2 = Borders[0].Vector; var Vector3 = Borders[0].Vector; var Normale1 = Borders[0].Normale; var Normale2 = Borders[0].Normale; var Normale3 = Borders[0].Normale; //var Center1 = new GeoCoordinate(new Latitude(Borders[0].Center.Longitude.Value), new Longitude(Borders[0].Center.Latitude.Value)); //var Center2 = new GeoCoordinate(new Latitude(Borders[1].Center.Longitude.Value), new Longitude(Borders[1].Center.Latitude.Value)); //var Center3 = new GeoCoordinate(new Latitude(Borders[2].Center.Longitude.Value), new Longitude(Borders[2].Center.Latitude.Value)); DrawLine(Center, Borders[0].Center, Brushes.Green, 1.0); DrawLine(Center, Borders[1].Center, Brushes.Green, 1.0); DrawLine(Center, Borders[2].Center, Brushes.Green, 1.0); } #endregion //var Center1 = new GeoCoordinate(new Latitude(49.7316155727453), new Longitude(10.1409612894059)); //var LineX_3_4 = new GeoLine(new GeoCoordinate(new Latitude(49.732745964269350), new Longitude(10.135724544525146)), // new GeoCoordinate(new Latitude(49.731761237693235), new Longitude(10.135746002197264))); //var Line_S3S4 = new GeoLine(new GeoCoordinate(new Latitude(49.732552), new Longitude(10.139216)), // new GeoCoordinate(new Latitude(49.731004), new Longitude(10.138913))); //var Line_S3S4Center2Center1 = new GeoLine(Line_S3S4.Center, // Center1); //var Intersection1 = Line_S3S4Center2Center1.Intersection(LineX_3_4); //DrawLine(Line_S3S4.Center, Intersection1, Brushes.Red, 1.0); //// ------------------------------------------------------------------------ //var LineX_7_8 = new GeoLine(new GeoCoordinate(new Latitude(49.729930425324014), new Longitude(10.137097835540771)), // new GeoCoordinate(new Latitude(49.729347879633465), new Longitude(10.138492584228516))); //var Line_S4S5 = new GeoLine(new GeoCoordinate(new Latitude(49.731004), new Longitude(10.138913)), // new GeoCoordinate(new Latitude(49.730237), new Longitude(10.140107))); //var Line_S4S5Center2Center1 = new GeoLine(Line_S4S5.Center, // Center1); //var Intersection2 = Line_S4S5Center2Center1.Intersection(LineX_7_8); //DrawLine(Line_S4S5.Center, Intersection2, Brushes.Red, 1.0); //// ------------------------------------------------------------------------ //var Center2 = new GeoCoordinate(new Latitude(49.7302216912131), new Longitude(10.1434879302979)); //var LineX_14_15 = new GeoLine(new GeoCoordinate(new Latitude(49.728695974976030), new Longitude(10.143170356750488)), // new GeoCoordinate(new Latitude(49.728987252607084), new Longitude(10.144414901733398))); //var Line_S5S7 = new GeoLine(new GeoCoordinate(new Latitude(49.730237), new Longitude(10.140107)), // new GeoCoordinate(new Latitude(49.730664), new Longitude(10.146802))); //var Line_S5S7Center2Center2 = new GeoLine(Line_S5S7.Center, // Center2); //var Intersection3 = Line_S5S7Center2Center2.Intersection(LineX_14_15); //DrawLine(Center2, Intersection3, Brushes.Red, 1.0); //// ------------------------------------------------------------------------ //var LineX_17_18 = new GeoLine(new GeoCoordinate(new Latitude(49.732413101183180), new Longitude(10.149564743041992)), // new GeoCoordinate(new Latitude(49.731469976708340), new Longitude(10.148684978485107))); //var Line_S7S6 = new GeoLine(new GeoCoordinate(new Latitude(49.730664), new Longitude(10.146802)), // new GeoCoordinate(new Latitude(49.731791), new Longitude(10.145903))); //var Line_S7S6Center2Center2 = new GeoLine(Line_S7S6.Center, // Center2); //var Intersection4 = Line_S7S6Center2Center2.Intersection(LineX_17_18); //DrawLine(Line_S7S6.Center, Intersection4, Brushes.Red, 1.0); //// ------------------------------------------------------------------------ //var Center3 = new GeoCoordinate(new Latitude(49.7318726185525), new Longitude(10.1424804925919)); //var LineX_23_24 = new GeoLine(new GeoCoordinate(new Latitude(49.734146738072006), new Longitude(10.144844055175781)), // new GeoCoordinate(new Latitude(49.733966442720840), new Longitude(10.142934322357178))); //var Line_S6S3 = new GeoLine(new GeoCoordinate(new Latitude(49.731791), new Longitude(10.145903)), // new GeoCoordinate(new Latitude(49.732552), new Longitude(10.139216))); //var Line_S6S3Center2Center3 = new GeoLine(Line_S6S3.Center, // Center3); //var Intersection5 = Line_S6S3Center2Center3.Intersection(LineX_23_24); //DrawLine(Line_S6S3.Center, Intersection5, Brushes.Red, 1.0); } }
private void DrawLine(GeoLine Line, Brush Stroke, Double StrokeThickness) { DrawLine(Line.P1, Line.P2, Stroke, StrokeThickness); }
private void Calc() { if (VoronoiFeatures.Count > 2) { #region Draw Delaunay if (DelaunayTriangleList == null) DelaunayTriangleList = VoronoiFeatures.DelaunayTriangulation().ToList(); if (DelaunayTriangleList != null) foreach (var DelaunayTriangle in DelaunayTriangleList) { var P1OnScreen = GeoCalculations.GeoCoordinate2ScreenXY(DelaunayTriangle.Triangle.P1, this.MapControl.ZoomLevel); var P2OnScreen = GeoCalculations.GeoCoordinate2ScreenXY(DelaunayTriangle.Triangle.P2, this.MapControl.ZoomLevel); var P3OnScreen = GeoCalculations.GeoCoordinate2ScreenXY(DelaunayTriangle.Triangle.P3, this.MapControl.ZoomLevel); ////DrawLine(P1OnScreen, P2OnScreen, Brushes.Blue, 1.0); ////DrawLine(P2OnScreen, P3OnScreen, Brushes.Blue, 1.0); ////DrawLine(P3OnScreen, P1OnScreen, Brushes.Blue, 1.0); //var GeoCircle = new GeoCircle(_Triangle.P1, _Triangle.P2, _Triangle.P3); var ScreenCircle = new Circle<Double>(new Pixel<Double>(P1OnScreen.X + this.MapControl.ScreenOffset.X, P1OnScreen.Y + this.MapControl.ScreenOffset.Y), new Pixel<Double>(P2OnScreen.X + this.MapControl.ScreenOffset.X, P2OnScreen.Y + this.MapControl.ScreenOffset.Y), new Pixel<Double>(P3OnScreen.X + this.MapControl.ScreenOffset.X, P3OnScreen.Y + this.MapControl.ScreenOffset.Y)); //var r1 = ScreenCircle.Center.DistanceTo(P1OnScreen.X + this.MapControl.ScreenOffset.X, P1OnScreen.Y + this.MapControl.ScreenOffset.Y); //var r2 = ScreenCircle.Center.DistanceTo(P2OnScreen.X + this.MapControl.ScreenOffset.X, P2OnScreen.Y + this.MapControl.ScreenOffset.Y); //var r3 = ScreenCircle.Center.DistanceTo(P3OnScreen.X + this.MapControl.ScreenOffset.X, P3OnScreen.Y + this.MapControl.ScreenOffset.Y); //var CenterOnScreen = GeoCalculations.GeoCoordinate2ScreenXY(GeoCircle.Center, this.MapControl.ZoomLevel); #region DrawCircumCircles if (DrawCircumCircles) { var CircumCircle = new Ellipse() { Width = ScreenCircle.Diameter, Height = ScreenCircle.Diameter, Stroke = Brushes.DarkGreen, StrokeThickness = 1.0 }; this.Children.Add(CircumCircle); //Canvas.SetLeft(CircumCircle, CenterOnScreen.X + this.MapControl.ScreenOffset.X); //Canvas.SetTop (CircumCircle, CenterOnScreen.Y + this.MapControl.ScreenOffset.Y); Canvas.SetLeft(CircumCircle, ScreenCircle.X - ScreenCircle.Radius);// + this.MapControl.ScreenOffset.X); Canvas.SetTop (CircumCircle, ScreenCircle.Y - ScreenCircle.Radius);// + this.MapControl.ScreenOffset.Y); } #endregion } foreach (var tr1 in DelaunayTriangleList) tr1.Neighbors.Clear(); HashSet<GeoCoordinate> tr1_h, tr2_h; IEnumerable<GeoCoordinate> Intersection; foreach (var tr1 in DelaunayTriangleList) { foreach (var tr2 in DelaunayTriangleList) { tr1_h = new HashSet<GeoCoordinate>(); tr1_h.Add(tr1.Triangle.P1); tr1_h.Add(tr1.Triangle.P2); tr1_h.Add(tr1.Triangle.P3); tr2_h = new HashSet<GeoCoordinate>(); tr2_h.Add(tr2.Triangle.P1); tr2_h.Add(tr2.Triangle.P2); tr2_h.Add(tr2.Triangle.P3); Intersection = tr1_h.Intersect(tr2_h); if (Intersection.Count() == 2) { tr1.Neighbors.Add(tr2); tr2.Neighbors.Add(tr1); foreach (var bo in tr1.Triangle.Borders) if (Intersection.Contains(bo.P1) && Intersection.Contains(bo.P2)) bo.Tags.Add("shared"); foreach (var bo in tr2.Triangle.Borders) if (Intersection.Contains(bo.P1) && Intersection.Contains(bo.P2)) bo.Tags.Add("shared"); } } } var aaa = DelaunayTriangleList.SelectMany(v => v.Triangle.Borders).Select(v => v.Tags); foreach (var DelaunayTriangle in DelaunayTriangleList) foreach (var Edge in DelaunayTriangle.Triangle.Borders) { DrawLine(GeoCalculations.GeoCoordinate2ScreenXY(Edge.P1, this.MapControl.ZoomLevel), GeoCalculations.GeoCoordinate2ScreenXY(Edge.P2, this.MapControl.ZoomLevel), (Edge.Tags.Contains("shared")) ? Brushes.LightBlue : Brushes.Blue, 1.0); } foreach (var tr1 in DelaunayTriangleList)//.Skip(2).Take(1)) { var Borders = tr1.Triangle.Borders.ToList(); var Center = new GeoLine(Borders[0].Center, Borders[0].Normale). Intersection(new GeoLine(Borders[1].Center, Borders[1].Normale)); var Vector1 = Borders[0].Vector; var Vector2 = Borders[0].Vector; var Vector3 = Borders[0].Vector; var Normale1 = Borders[0].Normale; var Normale2 = Borders[0].Normale; var Normale3 = Borders[0].Normale; //var Center1 = new GeoCoordinate(new Latitude(Borders[0].Center.Longitude.Value), new Longitude(Borders[0].Center.Latitude.Value)); //var Center2 = new GeoCoordinate(new Latitude(Borders[1].Center.Longitude.Value), new Longitude(Borders[1].Center.Latitude.Value)); //var Center3 = new GeoCoordinate(new Latitude(Borders[2].Center.Longitude.Value), new Longitude(Borders[2].Center.Latitude.Value)); DrawLine(Center, Borders[0].Center, Brushes.Green, 1.0); DrawLine(Center, Borders[1].Center, Brushes.Green, 1.0); DrawLine(Center, Borders[2].Center, Brushes.Green, 1.0); } #endregion //var Center1 = new GeoCoordinate(new Latitude(49.7316155727453), new Longitude(10.1409612894059)); //var LineX_3_4 = new GeoLine(new GeoCoordinate(new Latitude(49.732745964269350), new Longitude(10.135724544525146)), // new GeoCoordinate(new Latitude(49.731761237693235), new Longitude(10.135746002197264))); //var Line_S3S4 = new GeoLine(new GeoCoordinate(new Latitude(49.732552), new Longitude(10.139216)), // new GeoCoordinate(new Latitude(49.731004), new Longitude(10.138913))); //var Line_S3S4Center2Center1 = new GeoLine(Line_S3S4.Center, // Center1); //var Intersection1 = Line_S3S4Center2Center1.Intersection(LineX_3_4); //DrawLine(Line_S3S4.Center, Intersection1, Brushes.Red, 1.0); //// ------------------------------------------------------------------------ //var LineX_7_8 = new GeoLine(new GeoCoordinate(new Latitude(49.729930425324014), new Longitude(10.137097835540771)), // new GeoCoordinate(new Latitude(49.729347879633465), new Longitude(10.138492584228516))); //var Line_S4S5 = new GeoLine(new GeoCoordinate(new Latitude(49.731004), new Longitude(10.138913)), // new GeoCoordinate(new Latitude(49.730237), new Longitude(10.140107))); //var Line_S4S5Center2Center1 = new GeoLine(Line_S4S5.Center, // Center1); //var Intersection2 = Line_S4S5Center2Center1.Intersection(LineX_7_8); //DrawLine(Line_S4S5.Center, Intersection2, Brushes.Red, 1.0); //// ------------------------------------------------------------------------ //var Center2 = new GeoCoordinate(new Latitude(49.7302216912131), new Longitude(10.1434879302979)); //var LineX_14_15 = new GeoLine(new GeoCoordinate(new Latitude(49.728695974976030), new Longitude(10.143170356750488)), // new GeoCoordinate(new Latitude(49.728987252607084), new Longitude(10.144414901733398))); //var Line_S5S7 = new GeoLine(new GeoCoordinate(new Latitude(49.730237), new Longitude(10.140107)), // new GeoCoordinate(new Latitude(49.730664), new Longitude(10.146802))); //var Line_S5S7Center2Center2 = new GeoLine(Line_S5S7.Center, // Center2); //var Intersection3 = Line_S5S7Center2Center2.Intersection(LineX_14_15); //DrawLine(Center2, Intersection3, Brushes.Red, 1.0); //// ------------------------------------------------------------------------ //var LineX_17_18 = new GeoLine(new GeoCoordinate(new Latitude(49.732413101183180), new Longitude(10.149564743041992)), // new GeoCoordinate(new Latitude(49.731469976708340), new Longitude(10.148684978485107))); //var Line_S7S6 = new GeoLine(new GeoCoordinate(new Latitude(49.730664), new Longitude(10.146802)), // new GeoCoordinate(new Latitude(49.731791), new Longitude(10.145903))); //var Line_S7S6Center2Center2 = new GeoLine(Line_S7S6.Center, // Center2); //var Intersection4 = Line_S7S6Center2Center2.Intersection(LineX_17_18); //DrawLine(Line_S7S6.Center, Intersection4, Brushes.Red, 1.0); //// ------------------------------------------------------------------------ //var Center3 = new GeoCoordinate(new Latitude(49.7318726185525), new Longitude(10.1424804925919)); //var LineX_23_24 = new GeoLine(new GeoCoordinate(new Latitude(49.734146738072006), new Longitude(10.144844055175781)), // new GeoCoordinate(new Latitude(49.733966442720840), new Longitude(10.142934322357178))); //var Line_S6S3 = new GeoLine(new GeoCoordinate(new Latitude(49.731791), new Longitude(10.145903)), // new GeoCoordinate(new Latitude(49.732552), new Longitude(10.139216))); //var Line_S6S3Center2Center3 = new GeoLine(Line_S6S3.Center, // Center3); //var Intersection5 = Line_S6S3Center2Center3.Intersection(LineX_23_24); //DrawLine(Line_S6S3.Center, Intersection5, Brushes.Red, 1.0); } }