public static DistancePointLine ( System.Point p, System.Point a, System.Point b ) : double | ||
p | System.Point | The point to compute the distance for. |
a | System.Point | One point of the line. |
b | System.Point | Another point of the line (must be different to A). |
return | double |
public static double DistanceToLine(Point point, List <Point> points) { var minDist = Double.MaxValue; for (var i = 0; i < points.Count - 1; i++) { var dist = CGAlgorithms.DistancePointLine(point, points[i], points[i + 1]); if (dist < minDist) { minDist = dist; } } return(minDist); }
/// <summary> /// Returns the shortest distance to a line and also the index of the segment /// with that shortest distance. Segments count from zero to vertex count - 1. /// </summary> /// <param name="point"></param> /// <param name="points"></param> /// <returns></returns> public static (double Distance, int Segment) GetDistanceAndSegmentIndex(Point point, IList <Point> points) { var minDist = Double.MaxValue; int segment = 0; for (var i = 0; i < points.Count - 1; i++) { var dist = CGAlgorithms.DistancePointLine(point, points[i], points[i + 1]); if (dist < minDist) { minDist = dist; segment = i; } } return(minDist, segment); }