Exemplo n.º 1
0
        /// <summary>
        /// Gets the height at the point
        /// </summary>
        /// <param name="point"></param>
        /// <param name="Height"></param>
        /// <returns></returns>
        public bool TryGetHeight(IXYPoint point, out double?Height)
        {
            Height = null;


            try
            {
                if (oOracleConn == null)
                {
                    Connect();
                }

                // select sætning fra Frants.
                //select sdo_geor.getCellValue(rast,0,sdo_geometry(2001,32632,sdo_point_type(719000,6178000,null),null,null),1) val from dhm_test

                string select = string.Format("select sdo_geor.getCellValue(rast,0,sdo_geometry(2001,32632,sdo_point_type({0},{1},null),null,null),1) val from {2}", point.X, point.Y, TableName);

                var com = oOracleConn.CreateCommand();

                com.CommandText = select;

                Height = Convert.ToDouble(com.ExecuteScalar());

                return(true);
            }
            catch (Exception e)
            {
                return(false);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Calculates the distance from a polyline to a point in the plane.
        /// The algorithm decides weather the point lies besides the line
        /// segment in which case the distance is the length along a line
        /// perpendicular to the line. Alternatively the distance is the
        /// smallest of the distances to either endpoint.
        /// </summary>
        /// <param name="line">Line</param>
        /// <param name="point">Point</param>
        /// <returns>
        ///	<p>Length of the shortest path between the line and the point.</p>
        /// </returns>
        protected static double CalculateLineToPointDistance(XYLine line, IXYPoint point)
        {
            double dist = 0;
            double a    = Math.Sqrt((line.P2.X - point.X) * (line.P2.X - point.X) + (line.P2.Y - point.Y) * (line.P2.Y - point.Y));
            double b    = Math.Sqrt((line.P2.X - line.P1.X) * (line.P2.X - line.P1.X) + (line.P2.Y - line.P1.Y) * (line.P2.Y - line.P1.Y));
            double c    = Math.Sqrt((line.P1.X - point.X) * (line.P1.X - point.X) + (line.P1.Y - point.Y) * (line.P1.Y - point.Y));

            if ((a == 0) || (c == 0))
            {
                dist = 0;
            }
            else if (b == 0)
            {
                dist = a;
            }
            else
            {
                double alpha = Math.Acos((b * b + c * c - a * a) / (2 * b * c));
                double beta  = Math.Acos((a * a + b * b - c * c) / (2 * a * b));
                if (Math.Max(alpha, beta) < Math.PI / 2)
                {
                    dist = Math.Abs((line.P2.X - line.P1.X) * (line.P1.Y - point.Y) - (line.P1.X - point.X) * (line.P2.Y - line.P1.Y)) / b;
                }
                else
                {
                    dist = Math.Min(a, c);
                }
            }
            return(dist);
        }
Exemplo n.º 3
0
        public static ModelVisual3D Representation3D(this XYPolygon Poly, IXYPoint refpoint, double height)
        {
            MeshBuilder mb  = new MeshBuilder();
            var         pts = new Point3DCollection();

            foreach (var p in Poly.Points)
            {
                pts.Add(new Point3D(refpoint.X - p.X, refpoint.Y - p.Y, height));
            }

            // POLYGONS (flat and convex)
            var poly3D = new Polygon3D(pts);
            // Transform the polygon to 2D
            var poly2D = poly3D.Flatten();
            // Triangulate
            var tri = poly2D.Triangulate();

            if (tri != null)
            {
                // Add the triangle indices with the 3D points
                mb.Append(pts, tri);
            }

            var m = MaterialHelper.CreateMaterial(Colors.DimGray, 0.5);

            var mv3D = new ModelVisual3D();

            mv3D.Content = new GeometryModel3D(mb.ToMesh(), m);
            return(mv3D);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Returns the height above mean sea level from "den digitale højdemodel" with two decimals.
        /// Coordinates must be UTM
        /// A request takes almost 1 second
        /// </summary>
        /// <param name="point"></param>
        /// <returns></returns>
        public static bool TryGetHeight(IXYPoint point, int UTMZone, out double?Height)
        {
            Height = null;
            string url = String.Format("http://kmswwwudv1.kms.dk/FindMinHoejde/Default.aspx?display=show&csIn=utm{2}_euref89&csOut=utm32_euref89&x={0}&y={1}&c=dk", point.X, point.Y, UTMZone);

            HttpWebRequest  request  = (HttpWebRequest)WebRequest.Create(url);
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            string resultString;

            using (StreamReader streamReader1 = new StreamReader(response.GetResponseStream()))
            {
                resultString = streamReader1.ReadToEnd();
            }

            int start = resultString.LastIndexOf("</strong>") + 9;
            int end   = resultString.LastIndexOf("m</span>");

            if (start != -1 & end != -1)
            {
                string parsestring = resultString.Substring(start, end - start);
                Height = double.Parse(parsestring, new CultureInfo("da-DK", false));
                return(true);
            }
            return(false);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Returns the distance
        /// </summary>
        /// <param name="Other"></param>
        /// <returns></returns>
        public double GetDistance(IXYPoint Other)
        {
            double diff_N = this.Y - Other.Y;
            double diff_E = this.X - Other.X;

            return(Math.Sqrt(Math.Pow(diff_N, 2.0) + Math.Pow(diff_E, 2.0)));
        }
Exemplo n.º 6
0
    /// <summary>
    /// Returns the height above mean sea level from "den digitale højdemodel" with two decimals. 
    /// Coordinates must be UTM
    /// A request takes almost 1 second
    /// </summary>
    /// <param name="point"></param>
    /// <returns></returns>
    public static bool TryGetHeight(IXYPoint point, int UTMZone, out double? Height)
    {
      Height = null;
      string url = String.Format("http://kmswwwudv1.kms.dk/FindMinHoejde/Default.aspx?display=show&csIn=utm{2}_euref89&csOut=utm32_euref89&x={0}&y={1}&c=dk", point.X, point.Y, UTMZone);

      HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
      HttpWebResponse response = (HttpWebResponse)request.GetResponse();

      string resultString;

      using (StreamReader streamReader1 = new StreamReader(response.GetResponseStream()))
      {
        resultString = streamReader1.ReadToEnd();
      }

      int start = resultString.LastIndexOf("</strong>") + 9;
      int end = resultString.LastIndexOf("m</span>");

      if(start!=-1 & end!= -1)
      {
        string parsestring = resultString.Substring(start, end - start);
        Height =double.Parse(parsestring, new CultureInfo("da-DK", false));
        return true;
      }
      return false;
    }
Exemplo n.º 7
0
    /// <summary>
    /// Method splitted to permit testing without reading DHI CrossSection
    /// </summary>
    /// <param name="P1"></param>
    /// <param name="P2"></param>
    /// <param name="Chainage"></param>
    public void SetPoints(IXYPoint P1, IXYPoint P2, double Chainage1, double Chainage2, double Chainage)
    {
      double dx = P2.X - P1.X;
      double dy = P2.Y - P1.Y;
      double dchainage = (Chainage - Chainage1)/( Chainage2 - Chainage1);

      MidStreamLocation = new XYPoint(P1.X + dchainage * dx, P1.Y + dchainage * dy); 

      double lenght = Math.Pow(Math.Pow(dx,2)+ Math.Pow(dy,2),0.5);

      UnityVector = new XYPoint(dx / lenght, dy / lenght);

      //Now build the line where the cross section is located.
      if (_cs != null)
      {
        Line = new XYPolyline();
        //MidPoint is set to where Marker 2 is placed
        double xOffset = _xsec.LowestPoint.X;

        for (int i = 0; i < _xsec.Points.Count(); i++)
        {
          Line.Points.Add(new XYPoint(MidStreamLocation.X - UnityVector.Y * (_xsec.Points[i].X - xOffset), MidStreamLocation.Y + UnityVector.X * (_xsec.Points[i].X - xOffset)));
        }
      }
    }
Exemplo n.º 8
0
        private double?FindHeight(IXYPoint point)
        {
            double?height;

            TryFindDemHeight(point, out height);
            return(height);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Method splitted to permit testing without reading DHI CrossSection
        /// </summary>
        /// <param name="P1"></param>
        /// <param name="P2"></param>
        /// <param name="Chainage"></param>
        public void SetPoints(IXYPoint P1, IXYPoint P2, double Chainage1, double Chainage2, double Chainage)
        {
            double dx        = P2.X - P1.X;
            double dy        = P2.Y - P1.Y;
            double dchainage = (Chainage - Chainage1) / (Chainage2 - Chainage1);

            MidStreamLocation = new XYPoint(P1.X + dchainage * dx, P1.Y + dchainage * dy);

            double lenght = Math.Pow(Math.Pow(dx, 2) + Math.Pow(dy, 2), 0.5);

            UnityVector = new XYPoint(dx / lenght, dy / lenght);

            //Now build the line where the cross section is located.
            if (_cs != null)
            {
                Line = new XYPolyline();
                //MidPoint is set to where Marker 2 is placed
                double xOffset = _xsec.LowestPoint.X;

                for (int i = 0; i < _xsec.Points.Count(); i++)
                {
                    Line.Points.Add(new XYPoint(MidStreamLocation.X - UnityVector.Y * (_xsec.Points[i].X - xOffset), MidStreamLocation.Y + UnityVector.X * (_xsec.Points[i].X - xOffset)));
                }
            }
        }
Exemplo n.º 10
0
 /// <summary>
 /// Checks if the lines lineA and lineB shares a point either as a real
 /// crossing point or as a shared end point or a end point of the one
 /// line being in the other line.
 /// </summary>
 /// <param name="Linea">Line.</param>
 /// <param name="Lineb">Line.</param>
 /// <param name="intersectionPoint">Point.</param>
 /// <returns>
 ///	<p>True if lineA and lineB has shared point. False otherwise</p>
 ///	<p>The shared point if any is returned in the intersectionPoint
 ///	parameter that is called by reference</p>
 /// </returns>
 protected static bool IntersectionPoint(XYLine Linea, XYLine Lineb, ref IXYPoint intersectionPoint)
 {
     //Jag: this should be call TryGetValue and ref should be out
     if (DoLineSegmentsIntersect(Linea, Lineb))
     {
         intersectionPoint = CalculateIntersectionPoint(Linea, Lineb);
         return(true);
     }
     if (IsPointInLine(Linea.P2, Lineb))
     {
         intersectionPoint = Linea.P2;
         return(true);
     }
     if (IsPointInLine(Lineb.P2, Linea))
     {
         intersectionPoint = Lineb.P2;
         return(true);
     }
     if (IsPointInLine(Lineb.P1, Linea))
     {
         intersectionPoint = Lineb.P1;
         return(true);
     }
     if (IsPointInLine(Linea.P1, Lineb))
     {
         intersectionPoint = Linea.P1;
         return(true);
     }
     return(false);
 }
Exemplo n.º 11
0
    /// <summary>
    /// Gets the height at the point
    /// </summary>
    /// <param name="point"></param>
    /// <param name="Height"></param>
    /// <returns></returns>
    public bool TryGetHeight(IXYPoint point, out double? Height)
    {

      Height = null;


      try
      {
        if (oOracleConn == null)
          Connect();

        // select sætning fra Frants.
        //select sdo_geor.getCellValue(rast,0,sdo_geometry(2001,32632,sdo_point_type(719000,6178000,null),null,null),1) val from dhm_test

        string select = string.Format("select sdo_geor.getCellValue(rast,0,sdo_geometry(2001,32632,sdo_point_type({0},{1},null),null,null),1) val from {2}", point.X, point.Y, TableName);

        var com = oOracleConn.CreateCommand();

        com.CommandText = select;

        Height = Convert.ToDouble(com.ExecuteScalar());

        return true;
      }
      catch (Exception e)
      {
        return false;
      }
    }
Exemplo n.º 12
0
        /// <summary>
        /// Constructor. Copies input line.
        /// </summary>
        /// <param name="line">Line to copy</param>
        public XYLine(XYLine line)
        {
            _p1 = new XYPoint();
            _p2 = new XYPoint();

            _p1.X = line.P1.X;
            _p1.Y = line.P1.Y;
            _p2.X = line.P2.X;
            _p2.Y = line.P2.Y;
        }
Exemplo n.º 13
0
    /// <summary>
		/// Constructor.
		/// </summary>
		/// <param name="point1">Line start point</param>
		/// <param name="point2">Line end point</param>
    /// <returns>None</returns>
    public XYLine(IXYPoint point1, IXYPoint point2)
		{
      //JAG: Hvorfor beholder den ikke referencerne i stedet for at kopiere værdierne
			_p1 = new XYPoint();
			_p2 = new XYPoint();

			_p1.X = point1.X;
			_p1.Y = point1.Y;;
			_p2.X = point2.X;
			_p2.Y = point2.Y;
		}
Exemplo n.º 14
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="point1">Line start point</param>
        /// <param name="point2">Line end point</param>
        /// <returns>None</returns>
        public XYLine(IXYPoint point1, IXYPoint point2)
        {
            //JAG: Hvorfor beholder den ikke referencerne i stedet for at kopiere værdierne
            _p1 = new XYPoint();
            _p2 = new XYPoint();

            _p1.X = point1.X;
            _p1.Y = point1.Y;;
            _p2.X = point2.X;
            _p2.Y = point2.Y;
        }
Exemplo n.º 15
0
    public static XYPolygon GetSquare(double area, IXYPoint LowerLeft)
    {
      double length = Math.Pow(area, 0.5);
      XYPolygon pol = new XYPolygon();
      pol.Points.Add(LowerLeft);
      pol.Points.Add(new XYPoint(LowerLeft.X + length, LowerLeft.Y));

      pol.Points.Add(new XYPoint(LowerLeft.X + length, LowerLeft.Y + length));
      pol.Points.Add(new XYPoint(LowerLeft.X, LowerLeft.Y + length));

      return pol;
    }
Exemplo n.º 16
0
        public static XYPolygon GetSquare(double area, IXYPoint LowerLeft)
        {
            double    length = Math.Pow(area, 0.5);
            XYPolygon pol    = new XYPolygon();

            pol.Points.Add(LowerLeft);
            pol.Points.Add(new XYPoint(LowerLeft.X + length, LowerLeft.Y));

            pol.Points.Add(new XYPoint(LowerLeft.X + length, LowerLeft.Y + length));
            pol.Points.Add(new XYPoint(LowerLeft.X, LowerLeft.Y + length));

            return(pol);
        }
Exemplo n.º 17
0
        /// <summary>
        /// Returns the height at the point using the method selected with the enums
        /// </summary>
        /// <param name="point"></param>
        /// <param name="height"></param>
        /// <returns></returns>
        public bool TryFindDemHeight(IXYPoint point, out double?height)
        {
            height = null;

            switch (DEMSource)
            {
            case SourceType.Oracle:
                return(Oracle.TryGetHeight(point, out height));

            case SourceType.KMSWeb:
                return(KMSData.TryGetHeight(point, 32, out height));

            case SourceType.DFS2:
                int col = DFSdem.GetColumnIndex(point.X);
                int row = DFSdem.GetRowIndex(point.Y);
                if (col >= 0 & row >= 0)
                {
                    height = DFSdem.GetData(0, 1)[row, col];
                    return(true);
                }
                else
                {
                    return(false);
                }

            default:
                return(false);

            case SourceType.HydroInform:
            {
                XYPoint p = point as XYPoint;
                if (LDC.State == System.ServiceModel.CommunicationState.Faulted)
                {
                    return(false);
                }
                var d = LDC.GetHeight(p.Latitude, p.Longitude);
                if (d.HasValue)
                {
                    height = d.Value;
                }
                return(d.HasValue);
            }
            }
            return(false);
        }
Exemplo n.º 18
0
        /// <summary>
        /// Calculate intersection point between two line segments.
        /// </summary>
        /// <param name="p1">First point in first line</param>
        /// <param name="p2">Second point in first line</param>
        /// <param name="p3">First point in second line</param>
        /// <param name="p4">Second point in second line</param>
        /// <returns>Intersection point</returns>
        public static XYPoint CalculateIntersectionPoint(IXYPoint p1, IXYPoint p2, IXYPoint p3, IXYPoint p4)
        {
            if (!DoLineSegmentsIntersect(p1, p2, p3, p4))
            {
                throw new System.Exception("Attempt to calculate intersection point between non intersecting lines. CalculateIntersectionPoint failed.");
            }

            XYPoint interSectionPoint = new XYPoint();

            double a = p1.X * p2.Y - p2.X * p1.Y;
            double b = p3.X * p4.Y - p4.X * p3.Y;
            double c = (p1.X - p2.X) * (p3.Y - p4.Y) - (p3.X - p4.X) * (p1.Y - p2.Y);

            interSectionPoint.X = (a * (p3.X - p4.X) - (b * (p1.X - p2.X))) / c;
            interSectionPoint.Y = (a * (p3.Y - p4.Y) - (b * (p1.Y - p2.Y))) / c;

            return(interSectionPoint);
        }
Exemplo n.º 19
0
        /// <summary>
        /// Finds the shortest distance between any line segment of the polyline
        /// and the point.
        /// </summary>
        /// <param name="polyLine">PolyLine.</param>
        /// <param name="point">Point</param>
        /// <returns>
        ///	<p>Length of the shortest path between the polyline and the point.</p>
        /// </returns>
        public static double CalculatePolylineToPointDistance(XYPolyline polyLine, IXYPoint point)
        {
            double dist = 0;
            int    i    = 0;

            while (i < polyLine.Points.Count - 1)
            {
                if (i == 0)
                {
                    dist = CalculateLineToPointDistance(polyLine.GetLine(0), point);
                }
                else
                {
                    dist = Math.Min(dist, CalculateLineToPointDistance(polyLine.GetLine(i), point));
                }
                i++;
            }
            return(dist);
        }
Exemplo n.º 20
0
        public void Write(GeoRefData geodata)
        {
            double[]           Xs   = null;
            double[]           Ys   = null;
            ShapeLib.ShapeType type = ShapeLib.ShapeType.NullShape;

            if (geodata.Geometry is IXYPoint)
            {
                IXYPoint p = (IXYPoint)geodata.Geometry;
                type = ShapeLib.ShapeType.Point;
                Xs   = new double[] { p.X };
                Ys   = new double[] { p.Y };
            }
            else if (geodata.Geometry.GetType().Equals(typeof(XYPolyline)))
            {
                XYPolyline p = (XYPolyline)geodata.Geometry;
                type = ShapeLib.ShapeType.PolyLine;
                int npoints = p.Points.Count;

                Xs = new double[npoints];
                Ys = new double[npoints];

                for (int i = 0; i < npoints; i++)
                {
                    Xs[i] = p.Points[i].X;
                    Ys[i] = p.Points[i].Y;
                }
            }
            else if (geodata.Geometry.GetType().Equals(typeof(XYLine)))
            {
                XYLine p = (XYLine)geodata.Geometry;
                type = ShapeLib.ShapeType.PolyLine;
                int npoints = 2;

                Xs = new double[] { p.P1.X, p.P2.X };
                Ys = new double[] { p.P1.Y, p.P2.Y };;
            }

            else if (geodata.Geometry.GetType().Equals(typeof(XYPolygon)))
            {
                XYPolygon p = (XYPolygon)geodata.Geometry;
                type = ShapeLib.ShapeType.Polygon;
                int npoints = p.Points.Count;

                Xs = new double[npoints];
                Ys = new double[npoints];
                p.Points.Reverse();

                for (int i = 0; i < npoints; i++)
                {
                    Xs[i] = p.Points[i].X;
                    Ys[i] = p.Points[i].Y;
                }
                p.Points.Reverse();
            }
            else if (geodata.Geometry.GetType().Equals(typeof(MultiPartPolygon)))
            {
                MultiPartPolygon p = (MultiPartPolygon)geodata.Geometry;
                type = ShapeLib.ShapeType.Polygon;
                int npoints = p.Polygons.Sum(pol => pol.Points.Count);

                foreach (var poly in p.Polygons)
                {
                    poly.Points.Reverse();
                }

                Xs = new double[npoints];
                Ys = new double[npoints];
                int i = 0;
                foreach (var point in p.Polygons.SelectMany(pol => pol.Points))
                {
                    Xs[i] = point.X;
                    Ys[i] = point.Y;
                    i++;
                }
                foreach (var poly in p.Polygons)
                {
                    poly.Points.Reverse();
                }
            }

            if (_shapePointer == IntPtr.Zero)
            {
                _shapePointer = ShapeLib.SHPCreate(_fileName, type);
            }

            if (_shapePointer == IntPtr.Zero)
            {
                throw new Exception("Could not create: " + Path.GetFullPath(_fileName) + "\nMake sure directory exists.");
            }


            IntPtr obj;

            if (geodata.Geometry.GetType().Equals(typeof(MultiPartPolygon)))
            {
                MultiPartPolygon p = (MultiPartPolygon)geodata.Geometry;

                int[] partstarts = new int[p.Polygons.Count];
                partstarts[0] = 0;
                ShapeLib.PartType[] partype = new ShapeLib.PartType[p.Polygons.Count];
                for (int i = 0; i < partype.Count(); i++)
                {
                    partype[i] = ShapeLib.PartType.Ring;
                }

                for (int i = 1; i < partstarts.Count(); i++)
                {
                    partstarts[i] = partstarts[i - 1] + p.Polygons[i - 1].Points.Count;
                }


                obj = ShapeLib.SHPCreateObject(type, -1, partstarts.Count(), partstarts, partype, Xs.Count(), Xs, Ys, null, null);
            }
            else
            {
                obj = ShapeLib.SHPCreateSimpleObject(type, Xs.Count(), Xs, Ys, null);
            }
            ShapeLib.SHPWriteObject(_shapePointer, -1, obj);
            ShapeLib.SHPDestroyObject(obj);
            _dbf.WriteData(geodata.Data);

            NoOfEntries++;
        }
Exemplo n.º 21
0
 public double? GetHeight(IXYPoint point)
 {
   return GetHeight(point.X, point.Y);
 }
Exemplo n.º 22
0
		/// <summary>
		/// OverLoad of DoLineSegmentsIntersect(x1, y1, x2, y2, x3, y3, x4, y4)
		/// </summary>
		/// <param name="p1">First point in first line</param>
		/// <param name="p2">Second point in first line</param>
		/// <param name="p3">First point in second line</param>
		/// <param name="p4">Second point in second line</param>
		/// <returns>true if the line segmenst intersects otherwise false</returns>
    public static bool DoLineSegmentsIntersect(IXYPoint p1, IXYPoint p2, IXYPoint p3, IXYPoint p4)
		{
			return DoLineSegmentsIntersect(p1.X, p1.Y, p2.X, p2.Y, p3.X, p3.Y, p4.X, p4.Y);
		}
Exemplo n.º 23
0
    /// <summary>
    /// Interpolates x, y and height. Does not put in lat-long
    /// </summary>
    /// <param name="Point"></param>
    /// <param name="OtherPoint"></param>
    /// <param name="Distance"></param>
    /// <returns></returns>
    public static XYPoint InterpolatePoint(IXYPoint Point, IXYPoint OtherPoint, double Distance)
    {
      double relativedistance;
      if (Distance == 0)
        relativedistance = 0;
      else
      {
        double d = ((XYPoint)Point).GetDistance(OtherPoint);
        relativedistance = Distance / d;
      }

      XYPoint NewCoordinate = new XYPoint();
      NewCoordinate.X = Point.X - relativedistance * (Point.X - OtherPoint.X);
      NewCoordinate.Y = Point.Y - relativedistance * (Point.Y - OtherPoint.Y);
      //      NewCoordinate. = Point.Height.Value - relativedistance * (Point.Height.Value - OtherPoint.Height.Value);

      return NewCoordinate;
    }
Exemplo n.º 24
0
        /// <summary>
        /// The method calculates the intersection points of triangle a and b both
        /// of type XYPolygon.
        /// </summary>
        /// <param name="triangleA">triangle. The search is started along triangleA.</param>
        /// <param name="triangleB">triangle. Intersection with this triangle are sought.</param>
        /// <param name="p">Starting point for the search. p must be part of triangleA.</param>
        /// <param name="i">on input: End index for the first line segment of triangleA in the search.
        /// on output: End index for the last intersected line segment in triangleA.</param>
        /// <param name="j">on input: -1 if vertices before intersection is not to be added to list.
        /// on output: End index for last intersected line segment of triangleB.</param>
        /// <param name="intersectionPolygon">polygon eventuallu describing the
        /// intersection area between triangleA and triangleB</param>
        /// <returns>
        ///	The p, i, j and intersectionPolygon are called by reference and modified in the method.
        /// </returns>
        private static void Intersect(XYPolygon triangleA, XYPolygon triangleB,
                                      ref IXYPoint p, ref int i, ref int j,
                                      ref XYPolygon intersectionPolygon)
        {
            XYLine lineA;
            XYLine lineB;
            int    im1    = Decrease(i, 2); // "i-1"
            int    count1 = 0;
            bool   found  = false;

            while ((count1 < 3) && (!found))
            {
                lineA = triangleA.GetLine(im1);
                if (count1 == 0)
                {
                    lineA.P1.X = p.X;
                    lineA.P1.Y = p.Y;
                }
                double MinDist  = -1; // Distance used when a line is crossed more than once
                int    jm1      = 0;  // "j-1"
                int    jm1Store = -1;
                while (jm1 < 3)
                {
                    lineB = triangleB.GetLine(jm1);
                    found = IntersectionPoint(lineA, lineB, ref p);
                    double Dist = CalculatePointToPointDistance(lineA.P1, p);
                    if (Dist < EPSILON)
                    {
                        found = false;
                    }
                    if (found)
                    {
                        if ((MinDist < 0) || (Dist < MinDist))
                        {
                            MinDist  = Dist;
                            jm1Store = jm1;
                        }
                    }
                    jm1++;
                }
                if (jm1Store > -1)
                {
                    lineB = triangleB.GetLine(jm1Store);
                    found = IntersectionPoint(lineA, lineB, ref p);
                    XYPoint HelpCoordinate = new XYPoint(p.X, p.Y);
                    XYPoint HelpNode       = new XYPoint(HelpCoordinate);

                    intersectionPolygon.Points.Add(HelpNode);

                    j = Increase(jm1Store, 2);
                }
                if (!found)
                {
                    count1++;
                    im1 = Increase(im1, 2);
                    i   = Increase(i, 2);
                    if (j != -1)
                    {
                        XYPoint HelpCoordinate = new XYPoint(lineA.P2.X, lineA.P2.Y);
                        XYPoint HelpNode       = new XYPoint(HelpCoordinate);
                        intersectionPolygon.Points.Add(HelpNode);
                    }
                }
            }
            lineA = triangleA.GetLine(Decrease(i, 2));
            if (CalculatePointToPointDistance(p, lineA.P2) < EPSILON)
            {
                i = Increase(i, 2);
            }
            lineB = triangleB.GetLine(Decrease(j, 2));
            if (CalculatePointToPointDistance(p, lineB.P2) < EPSILON)
            {
                j = Increase(j, 2);
            }
        }
Exemplo n.º 25
0
    /// <summary>
    /// Returns the distance in two dimensions!
    /// </summary>
    /// <param name="Other"></param>
    /// <returns></returns>
    public double GetDistance(IXYPoint Other)
    {
      double diff_N = this.Y - Other.Y;
      double diff_E = this.X - Other.X;

      return Math.Sqrt(Math.Pow(diff_N, 2.0) + Math.Pow(diff_E, 2.0));
    }
Exemplo n.º 26
0
 /// <summary>
 /// Determines if a point in inside or outside a polygon.
 /// Works for both convex and concave polygons (Winding number test)
 /// </summary>
 /// <param name="point">Point</param>
 /// <param name="polygon">Polygon</param>
 /// <returns>
 ///	<p>true:  If the point is inside the polygon</p>
 ///	<p>false: Otherwise.</p>
 /// </returns>
 public static bool IsPointInPolygon(IXYPoint point, XYPolygon polygon)
 {
     return(IsPointInPolygon(point.X, point.Y, polygon));
 }
 private double? FindHeight(IXYPoint point)
 {
   double? height;
   TryFindDemHeight(point, out height);
   return height;
 }
Exemplo n.º 28
0
 /// <summary>
 /// Determines if a point is included in a lines interior. I.e. included
 /// in the line and not an endpoint.
 /// <p>Overload to:IsPointInLineInterior(double x, double y, XYLine line)</p>
 /// </summary>
 /// <param name="point">Point.</param>
 /// <param name="line">Line.</param>
 /// <returns>
 ///	<p>Determines if a point is included in a line.</p>
 /// </returns>
 protected static bool IsPointInLineInterior(IXYPoint point, XYLine line)
 {
     return(IsPointInLineInterior(point.X, point.Y, line));
 }
    /// <summary>
    /// Returns the height at the point using the method selected with the enums
    /// </summary>
    /// <param name="point"></param>
    /// <param name="height"></param>
    /// <returns></returns>
    public bool TryFindDemHeight(IXYPoint point, out double? height)
    {
      height = null;

      switch (DEMSource)
      {
        case SourceType.Oracle:
          return Oracle.TryGetHeight(point, out height);
        case SourceType.KMSWeb:
          return KMSData.TryGetHeight(point, 32, out height);
        case SourceType.DFS2:
          int col = DFSdem.GetColumnIndex(point.X);
          int row = DFSdem.GetRowIndex(point.Y);
          if (col >= 0 & row >= 0)
          {
            height = DFSdem.GetData(0, 1)[row, col];
            return true;
          }
          else
            return false;
        default:
          return false;
        case SourceType.HydroInform:
          {
            XYPoint p = point as XYPoint;
            if (LDC.State == System.ServiceModel.CommunicationState.Faulted)
              return false;
            var d = LDC.GetHeight(p.Latitude, p.Longitude);
            if (d.HasValue)
              height = d.Value;
            return d.HasValue;
          }
      }
      return false;
    }
Exemplo n.º 30
0
 /// <summary>
 /// Returns the distance between the two points.
 /// </summary>
 /// <param name="p1">Point</param>
 /// <param name="p2">Point</param>
 /// <returns>Point to point distance</returns>
 public static double CalculatePointToPointDistance(IXYPoint p1, IXYPoint p2)
 {
     return(Math.Sqrt((p1.X - p2.X) * (p1.X - p2.X) + (p1.Y - p2.Y) * (p1.Y - p2.Y)));
 }
Exemplo n.º 31
0
 public bool Contains(IXYPoint p)
 {
     return(Contains(p.X, p.Y));
     //return Polygons.Any(poly => poly.Contains(p));
 }
Exemplo n.º 32
0
    /// <summary>
		/// Constructor.
		/// </summary>
    /// <returns>None</returns>
		public XYLine()
		{
			_p1 = new XYPoint(); 
			_p2 = new XYPoint();
		}
Exemplo n.º 33
0
 /// <summary>
 /// OverLoad of DoLineSegmentsIntersect(x1, y1, x2, y2, x3, y3, x4, y4)
 /// </summary>
 /// <param name="p1">First point in first line</param>
 /// <param name="p2">Second point in first line</param>
 /// <param name="p3">First point in second line</param>
 /// <param name="p4">Second point in second line</param>
 /// <returns>true if the line segmenst intersects otherwise false</returns>
 public static bool DoLineSegmentsIntersect(IXYPoint p1, IXYPoint p2, IXYPoint p3, IXYPoint p4)
 {
     return(DoLineSegmentsIntersect(p1.X, p1.Y, p2.X, p2.Y, p3.X, p3.Y, p4.X, p4.Y));
 }
Exemplo n.º 34
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="x1">x-coordinate for line start point</param>
 /// <param name="y1">y-coordinate for line start point</param>
 /// <param name="x2">x-coordinate for line end point</param>
 /// <param name="y2">y-coordinate for line end point</param>
 /// <returns>None</returns>
 public XYLine(double x1, double y1, double x2, double y2)
 {
     _p1 = new XYPoint(x1, y1);
     _p2 = new XYPoint(x2, y2);
 }
Exemplo n.º 35
0
    public static List<Visual3D> Representation3D(this JupiterWell Well, IXYPoint refpoint)
    {
      List<Visual3D> wellrep = new List<Visual3D>();

      double x = refpoint.X - Well.X;
      double y = refpoint.Y - Well.Y;

      TruncatedConeVisual3D tcvw = new TruncatedConeVisual3D();
      tcvw.TopRadius = 0.5;
      tcvw.BaseRadius = 0.5;
      tcvw.Origin = new System.Windows.Media.Media3D.Point3D(x, y, Well.Terrain - Well.Depth.Value);
      if (Well.Depth.HasValue)
        tcvw.Height = Well.Depth.Value;
      else if (Well.Intakes.SelectMany(var => var.Screens).Count() > 0)
        tcvw.Height = Well.Intakes.SelectMany(var => var.Screens).Max(var2 => var2.DepthToBottom.Value);
      else
        tcvw.Height = Well.LithSamples.Max(var => var.Bottom);

      tcvw.Fill = new SolidColorBrush(Colors.Gray);
      wellrep.Add(tcvw);


      foreach (var sc in Well.Intakes.SelectMany(var => var.Screens))
      {
        if (sc.DepthToBottom.HasValue & sc.DepthToTop.HasValue)
        {
          TruncatedConeVisual3D tcv = new TruncatedConeVisual3D();
          tcv.TopRadius = 0.7;
          tcv.BaseRadius = 0.7;
          tcv.Origin = new System.Windows.Media.Media3D.Point3D(x, y, sc.BottomAsKote.Value);
          tcv.Height = sc.TopAsKote.Value - sc.BottomAsKote.Value;
          tcv.Fill = new SolidColorBrush(Colors.Black);
          wellrep.Add(tcv);
        }
      }

      foreach (var l in Well.LithSamples)
      {
        if (l.Top != -999 & l.Bottom != -999)
        {
          TruncatedConeVisual3D tcv = new TruncatedConeVisual3D();
          tcv.TopRadius = 1;
          tcv.BaseRadius = 1;
          tcv.Origin = new System.Windows.Media.Media3D.Point3D(x, y, Well.Terrain - l.Bottom);
          tcv.Height = l.Bottom - l.Top;
          SolidColorBrush m;
          if (l.RockSymbol.ToLower().Contains("s"))
          {
            m = new SolidColorBrush(Colors.Blue);
          }
          else if (l.RockSymbol.ToLower().Contains("l"))
          {
            m = new SolidColorBrush(Colors.Red);
          }
          else
            m = new SolidColorBrush(Colors.Green);

          m.Opacity = 0.3;
          tcv.Fill = m;

          wellrep.Add(tcv);
          TextVisual3D txt = new TextVisual3D();
          txt.Center = new Point3D(x+3, y+3, Well.Terrain - (l.Bottom + l.Top)/2.0);
          txt.Text = l.RockSymbol;
          txt.Height = 1;
          wellrep.Add(txt);

        }

      }
      return wellrep;
    }
Exemplo n.º 36
0
 /// <summary>
 /// Returns true if the point is inside the polygon
 /// </summary>
 /// <param name="p"></param>
 /// <returns></returns>
 public bool Contains(IXYPoint p)
 {
     return(Contains(p.X, p.Y));
 }
Exemplo n.º 37
0
    public static ModelVisual3D Representation3D(this XYPolygon Poly, IXYPoint refpoint, double height)
    {
      MeshBuilder mb = new MeshBuilder();
      var pts = new Point3DCollection();

      foreach (var p in Poly.Points)
      {
        pts.Add(new Point3D(refpoint.X - p.X, refpoint.Y - p.Y, height));
      }

      // POLYGONS (flat and convex)
      var poly3D = new Polygon3D(pts);
      // Transform the polygon to 2D
      var poly2D = poly3D.Flatten();
      // Triangulate
      var tri = poly2D.Triangulate();
      if (tri != null)
      {
        // Add the triangle indices with the 3D points
        mb.Append(pts, tri);
      }

      var m = MaterialHelper.CreateMaterial(Colors.DimGray, 0.5);

      var mv3D = new ModelVisual3D();
      mv3D.Content = new GeometryModel3D(mb.ToMesh(), m);
      return mv3D;

    }
Exemplo n.º 38
0
 /// <summary>
 /// Returns unityvector holding the direction
 /// </summary>
 /// <param name="p1"></param>
 /// <param name="p2"></param>
 /// <returns></returns>
 public static XYPoint GetDirection(IXYPoint p1, IXYPoint p2)
 {
   MathNet.Numerics.LinearAlgebra.Double.DenseVector v = new MathNet.Numerics.LinearAlgebra.Double.DenseVector(2);
   v[0] = p2.X - p1.X;
   v[1] = p2.Y - p1.Y;
   v.Normalize(1);
   return new XYPoint(v[0], v[1]);
 }
Exemplo n.º 39
0
        public static List <Visual3D> Representation3D(this JupiterWell Well, IXYPoint refpoint)
        {
            List <Visual3D> wellrep = new List <Visual3D>();

            double x = refpoint.X - Well.X;
            double y = refpoint.Y - Well.Y;

            TruncatedConeVisual3D tcvw = new TruncatedConeVisual3D();

            tcvw.TopRadius  = 0.5;
            tcvw.BaseRadius = 0.5;
            tcvw.Origin     = new System.Windows.Media.Media3D.Point3D(x, y, Well.Terrain - Well.Depth.Value);
            if (Well.Depth.HasValue)
            {
                tcvw.Height = Well.Depth.Value;
            }
            else if (Well.Intakes.SelectMany(var => var.Screens).Count() > 0)
            {
                tcvw.Height = Well.Intakes.SelectMany(var => var.Screens).Max(var2 => var2.DepthToBottom.Value);
            }
            else
            {
                tcvw.Height = Well.LithSamples.Max(var => var.Bottom);
            }

            tcvw.Fill = new SolidColorBrush(Colors.Gray);
            wellrep.Add(tcvw);


            foreach (var sc in Well.Intakes.SelectMany(var => var.Screens))
            {
                if (sc.DepthToBottom.HasValue & sc.DepthToTop.HasValue)
                {
                    TruncatedConeVisual3D tcv = new TruncatedConeVisual3D();
                    tcv.TopRadius  = 0.7;
                    tcv.BaseRadius = 0.7;
                    tcv.Origin     = new System.Windows.Media.Media3D.Point3D(x, y, sc.BottomAsKote.Value);
                    tcv.Height     = sc.TopAsKote.Value - sc.BottomAsKote.Value;
                    tcv.Fill       = new SolidColorBrush(Colors.Black);
                    wellrep.Add(tcv);
                }
            }

            foreach (var l in Well.LithSamples)
            {
                if (l.Top != -999 & l.Bottom != -999)
                {
                    TruncatedConeVisual3D tcv = new TruncatedConeVisual3D();
                    tcv.TopRadius  = 1;
                    tcv.BaseRadius = 1;
                    tcv.Origin     = new System.Windows.Media.Media3D.Point3D(x, y, Well.Terrain - l.Bottom);
                    tcv.Height     = l.Bottom - l.Top;
                    SolidColorBrush m;
                    if (l.RockSymbol.ToLower().Contains("s"))
                    {
                        m = new SolidColorBrush(Colors.Blue);
                    }
                    else if (l.RockSymbol.ToLower().Contains("l"))
                    {
                        m = new SolidColorBrush(Colors.Red);
                    }
                    else
                    {
                        m = new SolidColorBrush(Colors.Green);
                    }

                    m.Opacity = 0.3;
                    tcv.Fill  = m;

                    wellrep.Add(tcv);
                    TextVisual3D txt = new TextVisual3D();
                    txt.Center = new Point3D(x + 3, y + 3, Well.Terrain - (l.Bottom + l.Top) / 2.0);
                    txt.Text   = l.RockSymbol;
                    txt.Height = 1;
                    wellrep.Add(txt);
                }
            }
            return(wellrep);
        }
Exemplo n.º 40
0
    /// <summary>
    /// Determines if a point in inside or outside a polygon.
    /// Works for both convex and concave polygons (Winding number test)
    /// </summary>
    /// <param name="point">Point</param>
    /// <param name="polygon">Polygon</param>
    /// <returns>
    ///	<p>true:  If the point is inside the polygon</p>
    ///	<p>false: Otherwise.</p>
    /// </returns>
    public static bool IsPointInPolygon(IXYPoint point, XYPolygon polygon)
    {
		  return IsPointInPolygon(point.X, point.Y, polygon);
    }  
Exemplo n.º 41
0
 /// <summary>
 /// Returns true if the location is with the model area
 /// </summary>
 /// <param name="Location"></param>
 /// <returns></returns>
 public bool IsInModelArea(IXYPoint Location)
 {
     return(IsInModelArea(Location.X, Location.Y));
 }
Exemplo n.º 42
0
 public XYZPoint GetXYZ(IXYPoint point)
 {
   return new XYZPoint() { X = point.X, Y = point.Y, Z = GetHeight(point).Value };
 }
Exemplo n.º 43
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <returns>None</returns>
 public XYLine()
 {
     _p1 = new XYPoint();
     _p2 = new XYPoint();
 }
Exemplo n.º 44
0
        /// <summary>
        /// Calculates the theis drawdown. Pumpingrate is positive for injection. Pumpingrate and transmissivity time units should be seconds
        /// </summary>
        /// <param name="PumpingWell"></param>
        /// <param name="PumpingRate"></param>
        /// <param name="Storativity"></param>
        /// <param name="Transmissivity"></param>
        /// <param name="Time"></param>
        /// <param name="ObservationPoint"></param>
        /// <returns></returns>
        public double Drawdown(IXYPoint PumpingWell, double PumpingRate, double Storativity, double Transmissivity, TimeSpan Time, IXYPoint ObservationPoint)
        {
            double r = XYGeometryTools.CalculatePointToPointDistance(PumpingWell, ObservationPoint);

            return((PumpingRate / (4 * Math.PI * Transmissivity)) * W(r, Storativity, Transmissivity, Time.TotalSeconds));
        }
Exemplo n.º 45
0
		/// <summary>
		/// Calculate intersection point between two line segments.
		/// </summary>
		/// <param name="p1">First point in first line</param>
		/// <param name="p2">Second point in first line</param>
		/// <param name="p3">First point in second line</param>
		/// <param name="p4">Second point in second line</param>
		/// <returns>Intersection point</returns>
		public static XYPoint CalculateIntersectionPoint(IXYPoint p1, IXYPoint p2, IXYPoint p3, IXYPoint p4)
		{
			if (!DoLineSegmentsIntersect(p1,p2,p3,p4))
			{
				throw new System.Exception("Attempt to calculate intersection point between non intersecting lines. CalculateIntersectionPoint failed.");
			}
			
			XYPoint interSectionPoint = new XYPoint();
			
			double a = p1.X * p2.Y - p2.X * p1.Y;
			double b = p3.X * p4.Y - p4.X * p3.Y;
			double c = (p1.X - p2.X) * (p3.Y - p4.Y) - (p3.X - p4.X) * (p1.Y - p2.Y);

			interSectionPoint.X = (a * (p3.X - p4.X) - (b * (p1.X - p2.X))) / c;
			interSectionPoint.Y = (a * (p3.Y - p4.Y) - (b * (p1.Y - p2.Y))) / c;

			return interSectionPoint;
		}
Exemplo n.º 46
0
 public static bool AIntersectionPoint(XYLine lineA, XYLine lineB, ref IXYPoint intersectionPoint)
 {
     return(IntersectionPoint(lineA, lineB, ref intersectionPoint));
 }
Exemplo n.º 47
0
    /// <summary>
    /// The method calculates the intersection points of triangle a and b both
    /// of type XYPolygon.
    /// </summary>
    /// <param name="triangleA">triangle. The search is started along triangleA.</param>
    /// <param name="triangleB">triangle. Intersection with this triangle are sought.</param>
    /// <param name="p">Starting point for the search. p must be part of triangleA.</param>
    /// <param name="i">on input: End index for the first line segment of triangleA in the search.
    /// on output: End index for the last intersected line segment in triangleA.</param>
    /// <param name="j">on input: -1 if vertices before intersection is not to be added to list.
    /// on output: End index for last intersected line segment of triangleB.</param>
    /// <param name="intersectionPolygon">polygon eventuallu describing the 
    /// intersection area between triangleA and triangleB</param>
    /// <returns>
    ///	The p, i, j and intersectionPolygon are called by reference and modified in the method.
    /// </returns>
    private static void Intersect (XYPolygon triangleA, XYPolygon triangleB, 
                                   ref IXYPoint p, ref  int i, ref int j, 
                                   ref XYPolygon intersectionPolygon)
    {
      XYLine lineA;
      XYLine lineB;
      int im1 = Decrease(i, 2); // "i-1"
      int count1 = 0;
      bool found = false;

      while ((count1 < 3) && (!found))
      {
        lineA = triangleA.GetLine(im1);
        if (count1 == 0)
        {
          lineA.P1.X = p.X;
          lineA.P1.Y = p.Y;
        }
        double MinDist = -1; // Distance used when a line is crossed more than once
        int jm1 = 0;         // "j-1"
        int jm1Store = -1;
        while (jm1 < 3)
        {
          lineB = triangleB.GetLine(jm1);
          found = IntersectionPoint(lineA, lineB, ref p);
          double Dist = CalculatePointToPointDistance(lineA.P1,p);
          if (Dist < EPSILON)
          {
            found = false;
          }
          if (found)
          {
            if ((MinDist < 0) || (Dist < MinDist))
            {
              MinDist = Dist;
              jm1Store = jm1;
            }
          }
          jm1++;
        }
        if ( jm1Store > -1 )
        {
          lineB = triangleB.GetLine(jm1Store);
          found = IntersectionPoint(lineA, lineB, ref p);          
		      XYPoint HelpCoordinate = new XYPoint(p.X, p.Y);
		      XYPoint HelpNode = new XYPoint(HelpCoordinate);

		      intersectionPolygon.Points.Add(HelpNode);

          j = Increase(jm1Store,2);  
        }
        if (!found)
        {
          count1++;
          im1 = Increase(im1,2);
          i = Increase(i,2);
          if (j!=-1) 
          {
		        XYPoint HelpCoordinate = new XYPoint(lineA.P2.X, lineA.P2.Y);
       			XYPoint HelpNode = new XYPoint(HelpCoordinate);
       			intersectionPolygon.Points.Add(HelpNode);
          }
        }
      }
      lineA = triangleA.GetLine(Decrease(i, 2));
      if ( CalculatePointToPointDistance(p, lineA.P2)<EPSILON )
      {
        i = Increase(i, 2);
      }
      lineB = triangleB.GetLine(Decrease(j, 2));
      if ( CalculatePointToPointDistance(p, lineB.P2)<EPSILON )
      {
        j = Increase(j, 2);
      }
    }
Exemplo n.º 48
0
    public XYPoint GetProjectedPoint(IXYPoint PointToProject)
    {
        double m = (P2.Y - P1.Y) / (P2.X - P1.X);
        double b = P1.Y - (m * P1.X);

        double x = (m * PointToProject.Y + PointToProject.X - m * b) / (m * m + 1);
        double y = (m * m * PointToProject.Y + m * PointToProject.X + b) / (m * m + 1);
     
        return new XYPoint(x, y);
    }
Exemplo n.º 49
0
		/// <summary>
		/// Returns the distance between the two points.
		/// </summary>
		/// <param name="p1">Point</param>
		/// <param name="p2">Point</param>
		/// <returns>Point to point distance</returns>
		public static double CalculatePointToPointDistance(IXYPoint p1, IXYPoint p2)
		{
		return Math.Sqrt( (p1.X-p2.X)*(p1.X-p2.X)+(p1.Y -p2.Y )*(p1.Y -p2.Y ) );
		}
Exemplo n.º 50
0
    /// <summary>
		/// Constructor.
		/// </summary>
		/// <param name="x1">x-coordinate for line start point</param>
		/// <param name="y1">y-coordinate for line start point</param>
		/// <param name="x2">x-coordinate for line end point</param>
		/// <param name="y2">y-coordinate for line end point</param>
    /// <returns>None</returns>
    public XYLine(double x1, double y1, double x2, double y2)
		{      
			_p1 = new XYPoint(x1,y1);
			_p2 = new XYPoint(x2,y2);
		}
Exemplo n.º 51
0
 /// <summary>
 /// Checks if the lines lineA and lineB shares a point either as a real 
 /// crossing point or as a shared end point or a end point of the one 
 /// line being in the other line.
 /// </summary>
 /// <param name="Linea">Line.</param>
 /// <param name="Lineb">Line.</param>
 /// <param name="intersectionPoint">Point.</param>
 /// <returns>
 ///	<p>True if lineA and lineB has shared point. False otherwise</p>
 ///	<p>The shared point if any is returned in the intersectionPoint 
 ///	parameter that is called by reference</p>
 /// </returns>
 protected static bool IntersectionPoint(XYLine Linea, XYLine Lineb, ref IXYPoint intersectionPoint)
 {
   //Jag: this should be call TryGetValue and ref should be out
   if( DoLineSegmentsIntersect(Linea, Lineb))
   {
     intersectionPoint = CalculateIntersectionPoint(Linea, Lineb);
     return true;
   }
   if( IsPointInLine(Linea.P2, Lineb))
   {
     intersectionPoint = Linea.P2;
     return true;
   }
   if( IsPointInLine(Lineb.P2, Linea))
   {
     intersectionPoint = Lineb.P2;
     return true;
   }
   if( IsPointInLine(Lineb.P1, Linea))
   {
     intersectionPoint = Lineb.P1;
     return true;
   }
   if( IsPointInLine(Linea.P1, Lineb))
   {
     intersectionPoint = Linea.P1;
     return true;
   }
   return false;
 }
Exemplo n.º 52
0
    /// <summary>
		/// Constructor. Copies input line.
		/// </summary>
		/// <param name="line">Line to copy</param>
		public XYLine(XYLine line)
		{
			_p1 = new XYPoint();
			_p2 = new XYPoint();

			_p1.X = line.P1.X;
			_p1.Y = line.P1.Y;
			_p2.X = line.P2.X;
			_p2.Y = line.P2.Y;
		}
Exemplo n.º 53
0
 /// <summary>
 /// Determines if a point is included in a lines interior. I.e. included 
 /// in the line and not an endpoint. 
 /// <p>Overload to:IsPointInLineInterior(double x, double y, XYLine line)</p>
 /// </summary>
 /// <param name="point">Point.</param>
 /// <param name="line">Line.</param>
 /// <returns>
 ///	<p>Determines if a point is included in a line.</p>
 /// </returns>
 protected static bool IsPointInLineInterior(IXYPoint point, XYLine line)
 {
   return IsPointInLineInterior( point.X, point.Y, line);
 }
Exemplo n.º 54
0
    /// <summary>
    /// Constructor.
    /// </summary>
    /// <returns>None</returns>
    public XYPoint(IXYPoint xypoint)
	  {
		  _x = xypoint.X;
		  _y = xypoint.Y;
	  }
Exemplo n.º 55
0
 /// <summary>
 /// Calculates the distance from a polyline to a point in the plane. 
 /// The algorithm decides weather the point lies besides the line 
 /// segment in which case the distance is the length along a line 
 /// perpendicular to the line. Alternatively the distance is the 
 /// smallest of the distances to either endpoint.
 /// </summary>
 /// <param name="line">Line</param>
 /// <param name="point">Point</param>
 /// <returns>
 ///	<p>Length of the shortest path between the line and the point.</p>
 /// </returns>
 protected static double CalculateLineToPointDistance (XYLine line, IXYPoint point)
 {
   double dist = 0;
   double a = Math.Sqrt((line.P2.X-point.X)*(line.P2.X-point.X) + (line.P2.Y-point.Y)*(line.P2.Y-point.Y));
   double b = Math.Sqrt((line.P2.X-line.P1.X)*(line.P2.X-line.P1.X)+(line.P2.Y-line.P1.Y)*(line.P2.Y-line.P1.Y));
   double c = Math.Sqrt((line.P1.X-point.X)*(line.P1.X-point.X)+(line.P1.Y-point.Y)*(line.P1.Y-point.Y));
   if ((a == 0) || (c == 0))
   {
     dist = 0;
   }
   else if (b == 0)
   {
     dist = a;
   }
   else
   {
     double alpha = Math.Acos((b*b+c*c-a*a)/(2*b*c));
     double beta = Math.Acos((a*a+b*b-c*c)/(2*a*b));
     if (Math.Max(alpha,beta)<Math.PI/2)
     {
       dist = Math.Abs((line.P2.X-line.P1.X)*(line.P1.Y-point.Y)-(line.P1.X-point.X)*(line.P2.Y-line.P1.Y))/b;
     }
     else
     {
       dist = Math.Min(a, c);
     }
   }
   return dist;
 }
Exemplo n.º 56
0
 /// <summary>
 /// Gets the id for a point
 /// </summary>
 /// <param name="point"></param>
 /// <returns></returns>
 public int GetID(IXYPoint point)
 {
   return GetID(point.X,point.Y);
 }
Exemplo n.º 57
0
 /// <summary>
 /// Finds the shortest distance between any line segment of the polyline 
 /// and the point.
 /// </summary>
 /// <param name="polyLine">PolyLine.</param>
 /// <param name="point">Point</param>
 /// <returns>
 ///	<p>Length of the shortest path between the polyline and the point.</p>
 /// </returns>
 public static double CalculatePolylineToPointDistance (XYPolyline polyLine, IXYPoint point)
 {
   double dist = 0;
   int i = 0;
   while (i < polyLine.Points.Count - 1) 
   {
     if (i == 0) 
     {
       dist = CalculateLineToPointDistance (polyLine.GetLine(0), point);
     }
     else
     {
       dist = Math.Min(dist, CalculateLineToPointDistance (polyLine.GetLine(i), point));
     }
     i++;
   }
   return dist;
 }
Exemplo n.º 58
0
 /// <summary>
 /// Gets the id for a point
 /// </summary>
 /// <param name="point"></param>
 /// <returns></returns>
 public int GetID(IXYPoint point)
 {
     return(GetID(point.X, point.Y));
 }
Exemplo n.º 59
0
    /// <summary>
    /// Does the same as CalculatePolylineToPointDistance but also returns the line number
    /// </summary>
    /// <param name="polyLine"></param>
    /// <param name="point"></param>
    /// <returns></returns>
    public static Tuple<int, double> GetClosetLine (XYPolyline polyLine, IXYPoint point)
    {
      
      double dist = double.MaxValue;
      int i = 0;
      int mini=0;
      while (i < polyLine.Points.Count - 1)
      {

          var newdist = CalculateLineToPointDistance(polyLine.GetLine(i), point);
        if(newdist<dist)
        {
          dist=newdist;
          mini =i;
        }
        i++;
      }
      return new Tuple<int, double>(mini, dist);
    }