Пример #1
0
        /// <summary>
        /// Returns the orientation index of the direction of the point <paramref name="q"/> relative to
        /// a directed infinite line specified by <c>p1-&gt;p2</c>.
        /// The index indicates whether the point lies to the <see cref="OrientationIndex.Left"/>
        /// or <see cref="OrientationIndex.Right"/> of the line, or lies on it <see cref="OrientationIndex.Collinear"/>.
        /// The index also indicates the orientation of the triangle formed by the three points
        /// (<see cref="OrientationIndex.CounterClockwise"/>, <see cref="OrientationIndex.Clockwise"/>, or
        /// <see cref="OrientationIndex.Straight"/> )
        /// </summary>
        /// <param name="p1">The origin point of the line vector</param>
        /// <param name="p2">The final point of the line vector</param>
        /// <param name="q">The point to compute the direction to</param>
        /// <returns>
        /// The <see cref="OrientationIndex"/> of q in regard to the vector <c>p1-&gt;p2</c>
        /// <list type="Table">
        /// <listheader>
        /// <term>Value</term><description>Description</description>
        /// </listheader>
        /// <item>
        /// <term><see cref="OrientationIndex.Collinear"/>, <see cref="OrientationIndex.Straight"/></term>
        /// <description><paramref name="q"/> is collinear with <c>p1-&gt;p2</c></description>
        /// </item>
        /// <item>
        /// <term><see cref="OrientationIndex.Clockwise"/>, <see cref="OrientationIndex.Right"/></term>
        /// <description><paramref name="q"/> is clockwise (right) from <c>p1-&gt;p2</c></description>
        /// </item>
        /// <item>
        /// <term><see cref="OrientationIndex.CounterClockwise"/>, <see cref="OrientationIndex.Left"/></term>
        /// <description><paramref name="q"/> is counter-clockwise (left) from <c>p1-&gt;p2</c></description>
        /// </item>
        /// </list>
        /// </returns>
        public static OrientationIndex Index(Coordinate p1, Coordinate p2, Coordinate q)
        {
            /**
             * MD - 9 Aug 2010 It seems that the basic algorithm is slightly orientation
             * dependent, when computing the orientation of a point very close to a
             * line. This is possibly due to the arithmetic in the translation to the
             * origin.
             *
             * For instance, the following situation produces identical results in spite
             * of the inverse orientation of the line segment:
             *
             * Coordinate p0 = new Coordinate(219.3649559090992, 140.84159161824724);
             * Coordinate p1 = new Coordinate(168.9018919682399, -5.713787599646864);
             *
             * Coordinate p = new Coordinate(186.80814046338352, 46.28973405831556); int
             * orient = orientationIndex(p0, p1, p); int orientInv =
             * orientationIndex(p1, p0, p);
             *
             * A way to force consistent results is to normalize the orientation of the
             * vector using the following code. However, this may make the results of
             * orientationIndex inconsistent through the triangle of points, so it's not
             * clear this is an appropriate patch.
             *
             */
            var res = (OrientationIndex)CGAlgorithmsDD.OrientationIndex(p1, p2, q);

            return(res); //(Orientation)CGAlgorithmsDD.OrientationIndex(p1, p2, q);
            // testing only
            //return ShewchuksDeterminant.orientationIndex(p1, p2, q);
            // previous implementation - not quite fully robust
            //return RobustDeterminant.orientationIndex(p1, p2, q);
        }
Пример #2
0
        private void CheckDD(Coordinate p1, Coordinate p2, Coordinate q1,
                             Coordinate q2, Coordinate intPt)
        {
            var  intPtDD = CGAlgorithmsDD.Intersection(p1, p2, q1, q2);
            bool isIn    = IsInSegmentEnvelopes(intPtDD);

            Debug.WriteLine("DD in env = " + isIn + "  --------------------- " + intPtDD);
            double distance = intPt.Distance(intPtDD);

            if (distance > 0.0001)
            {
                Debug.WriteLine("Distance = " + distance);
            }
        }