예제 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="line0"></param>
        /// <param name="line1"></param>
        /// <param name="locGeom"></param>
        private void ComputeMinDistance(ILineString line0, ILineString line1, GeometryLocation[] locGeom)
        {
            if (line0.EnvelopeInternal.Distance(line1.EnvelopeInternal) > _minDistance)
            {
                return;
            }
            IList <Coordinate> coord0 = line0.Coordinates;
            IList <Coordinate> coord1 = line1.Coordinates;

            // brute force approach!
            for (int i = 0; i < coord0.Count - 1; i++)
            {
                for (int j = 0; j < coord1.Count - 1; j++)
                {
                    double dist = CgAlgorithms.DistanceLineLine(
                        coord0[i], coord0[i + 1],
                        coord1[j], coord1[j + 1]);
                    if (dist < _minDistance)
                    {
                        _minDistance = dist;
                        LineSegment  seg0      = new LineSegment(coord0[i], coord0[i + 1]);
                        LineSegment  seg1      = new LineSegment(coord1[j], coord1[j + 1]);
                        Coordinate[] closestPt = seg0.ClosestPoints(seg1);
                        locGeom[0] = new GeometryLocation(line0, i, new Coordinate(closestPt[0]));
                        locGeom[1] = new GeometryLocation(line1, j, new Coordinate(closestPt[1]));
                    }
                    if (_minDistance <= _terminateDistance)
                    {
                        return;
                    }
                }
            }
        }
예제 #2
0
 /// <summary>
 /// Computes the distance between this line segment and another one.
 /// </summary>
 /// <param name="ls"></param>
 /// <returns></returns>
 public virtual double Distance(ILineSegmentBase ls)
 {
     return(CgAlgorithms.DistanceLineLine(P0, P1, new Coordinate(ls.P0), new Coordinate(ls.P1)));
 }