Пример #1
0
        /// <summary>
        /// Projects a point on a line passing through p and q
        /// </summary>
        /// <param name="pnt">The point to be projected</param>
        /// <param name="p">First point defining the line</param>
        /// <param name="q">Second point defining the line</param>
        /// <returns>The point <paramref name="pnt"/> projected on the specified line segment.</returns>
        public static Point ProjectOnLine(this Point pnt, Point p, Point q)
        {
            var v         = q - p;
            var t         = pnt.ProjectOnLine(p, v);
            var candidate = p + t * v;

            return(candidate);
        }
Пример #2
0
 /// <summary>
 /// Computes the distance from the given point to the given line.
 /// </summary>
 /// <param name="pnt">The point to compute the distance for</param>
 /// <param name="p">First point defining the line</param>
 /// <param name="q">Second point defining the line</param>
 /// <returns>The distance from <paramref name="pnt"/> to the line defined by <paramref name="p"/> and <paramref name="q"/>.</returns>
 public static double DistanceToLine(this Point pnt, Point p, Point q)
 {
     return((pnt - pnt.ProjectOnLine(p, q)).Length);
 }