コード例 #1
0
        //// temporary Coordinates to materialize points from the CoordinateSequence
        //private readonly Coordinate _p0 = new Coordinate();
        //private readonly Coordinate _p1 = new Coordinate();
        //private readonly Coordinate _q0 = new Coordinate();
        //private readonly Coordinate _q1 = new Coordinate();

        private double ComputeLineLineDistance(FacetSequence facetSeq)
        {
            // both linear - compute minimum segment-segment distance
            var minDistance = Double.MaxValue;

            var p0 = new Coordinate();
            var p1 = new Coordinate();
            var q0 = new Coordinate();
            var q1 = new Coordinate();

            for (int i = _start; i < _end - 1; i++)
            {
                for (int j = facetSeq._start; j < facetSeq._end - 1; j++)
                {
                    _pts.GetCoordinate(i, p0);
                    _pts.GetCoordinate(i + 1, p1);
                    facetSeq._pts.GetCoordinate(j, q0);
                    facetSeq._pts.GetCoordinate(j + 1, q1);

                    double dist = DistanceComputer.SegmentToSegment(p0, p1, q0, q1);
                    if (dist == 0.0)
                    {
                        return(0.0);
                    }
                    if (dist < minDistance)
                    {
                        minDistance = dist;
                    }
                }
            }
            return(minDistance);
        }
コード例 #2
0
ファイル: DistanceOp.cs プロジェクト: Smartico2020/Geo1
        /// <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;
            }
            var coord0 = line0.Coordinates;
            var coord1 = line1.Coordinates;

            // brute force approach!
            for (int i = 0; i < coord0.Length - 1; i++)
            {
                for (int j = 0; j < coord1.Length - 1; j++)
                {
                    double dist = DistanceComputer.SegmentToSegment(
                        coord0[i], coord0[i + 1],
                        coord1[j], coord1[j + 1]);
                    if (dist < _minDistance)
                    {
                        _minDistance = dist;
                        var seg0      = new LineSegment(coord0[i], coord0[i + 1]);
                        var seg1      = new LineSegment(coord1[j], coord1[j + 1]);
                        var closestPt = seg0.ClosestPoints(seg1);
                        locGeom[0] = new GeometryLocation(line0, i, closestPt[0]);
                        locGeom[1] = new GeometryLocation(line1, j, closestPt[1]);
                    }
                    if (_minDistance <= _terminateDistance)
                    {
                        return;
                    }
                }
            }
        }
コード例 #3
0
        private double ComputeDistanceLineLine(FacetSequence facetSeq, GeometryLocation[] locs)
        {
            // both linear - compute minimum segment-segment distance
            double minDistance = double.MaxValue;

            for (int i = _start; i < _end - 1; i++)
            {
                var p0 = _pts.GetCoordinate(i);
                var p1 = _pts.GetCoordinate(i + 1);
                for (int j = facetSeq._start; j < facetSeq._end - 1; j++)
                {
                    var q0 = facetSeq._pts.GetCoordinate(j);
                    var q1 = facetSeq._pts.GetCoordinate(j + 1);

                    double dist = DistanceComputer.SegmentToSegment(p0, p1, q0, q1);
                    if (dist < minDistance)
                    {
                        minDistance = dist;
                        if (locs != null)
                        {
                            UpdateNearestLocationsLineLine(i, p0, p1, facetSeq, j, q0, q1, locs);
                        }

                        if (minDistance <= 0)
                        {
                            return(minDistance);
                        }
                    }
                }
            }
            return(minDistance);
        }
コード例 #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="line0"></param>
        /// <param name="line1"></param>
        /// <param name="locGeom"></param>
        private void ComputeMinDistance(LineString line0, LineString line1, GeometryLocation[] locGeom)
        {
            if (line0.EnvelopeInternal.Distance(line1.EnvelopeInternal) > _minDistance)
            {
                return;
            }
            var coord0 = line0.Coordinates;
            var coord1 = line1.Coordinates;

            // brute force approach!
            for (int i = 0; i < coord0.Length - 1; i++)
            {
                // short-circuit if line segment is far from line
                var segEnv0 = new Envelope(coord0[i], coord0[i + 1]);
                if (segEnv0.Distance(line1.EnvelopeInternal) > _minDistance)
                {
                    continue;
                }

                for (int j = 0; j < coord1.Length - 1; j++)
                {
                    // short-circuit if line segments are far apart
                    var segEnv1 = new Envelope(coord1[j], coord1[j + 1]);
                    if (segEnv0.Distance(segEnv1) > _minDistance)
                    {
                        continue;
                    }

                    double dist = DistanceComputer.SegmentToSegment(
                        coord0[i], coord0[i + 1],
                        coord1[j], coord1[j + 1]);
                    if (dist < _minDistance)
                    {
                        _minDistance = dist;
                        var seg0      = new LineSegment(coord0[i], coord0[i + 1]);
                        var seg1      = new LineSegment(coord1[j], coord1[j + 1]);
                        var closestPt = seg0.ClosestPoints(seg1);
                        locGeom[0] = new GeometryLocation(line0, i, closestPt[0]);
                        locGeom[1] = new GeometryLocation(line1, j, closestPt[1]);
                    }
                    if (_minDistance <= _terminateDistance)
                    {
                        return;
                    }
                }
            }
        }
コード例 #5
0
        public void TestRandomDisjointCollinearSegments()
        {
            int n         = 1000000;
            int failCount = 0;

            for (int i = 0; i < n; i++)
            {
                //System.out.println(i);
                var seg = RandomDisjointCollinearSegments();
                if (0 == DistanceComputer.SegmentToSegment(seg[0], seg[1], seg[2], seg[3]))
                {
                    /*
                     * System.out.println("FAILED! - "
                     + WKTWriter.toLineString(seg[0], seg[1]) + "  -  "
                     + WKTWriter.toLineString(seg[2], seg[3]));
                     */
                    failCount++;
                }
            }
            Console.WriteLine("# failed = " + failCount + " out of " + n);
        }
コード例 #6
0
 /// <summary>
 /// Computes the distance between this line segment and another one.
 /// </summary>
 /// <param name="ls"></param>
 /// <returns></returns>
 public double Distance(LineSegment ls)
 {
     return(DistanceComputer.SegmentToSegment(_p0, _p1, ls._p0, ls._p1));
 }
コード例 #7
0
 public void TestDistanceLineLineDisjointCollinear()
 {
     Assert.AreEqual(1.999699, DistanceComputer.SegmentToSegment(
                         new Coordinate(0, 0), new Coordinate(9.9, 1.4),
                         new Coordinate(11.88, 1.68), new Coordinate(21.78, 3.08)), 0.000001);
 }