Exemple #1
0
        /// <summary>
        /// Computes the closest point on this line segment to another point.
        /// </summary>
        /// <param name="p">The point to find the closest point to.</param>
        /// <returns>
        /// A Coordinate which is the closest point on the line segment to the point p.
        /// </returns>
        public ICoordinate ClosestPoint(ICoordinate p)
        {
            var factor = ProjectionFactor(p);

            if (factor > 0 && factor < 1)
            {
                return(Project(p));
            }
            var dist0 = P0.Distance(p);
            var dist1 = P1.Distance(p);

            return(dist0 < dist1 ? P0 : P1);
        }
Exemple #2
0
        /// <summary>
        /// Computes the closest point on this line segment to another point.
        /// </summary>
        /// <param name="p">The point to find the closest point to.</param>
        /// <returns>
        /// A Coordinate which is the closest point on the line segment to the point p.
        /// </returns>
        public ICoordinate ClosestPoint(ICoordinate p)
        {
            double factor = ProjectionFactor(p);

            if (factor > 0 && factor < 1)
            {
                return(Project(p));
            }
            double dist0 = P0.Distance(p);
            double dist1 = P1.Distance(p);

            if (dist0 < dist1)
            {
                return(P0);
            }
            else
            {
                return(P1);
            }
        }