/// <summary> /// Searches for the two closests points /// </summary> /// <param name="intersectionPoints">List of intersection points</param> /// <returns>The points that are closests to each other</returns> public static Point ShortestDistanceBetweenCutPoints(List <Point> intersectionPoints, Point centroid) { List <ClosestToCentroid> DistancesToCentroid = new List <ClosestToCentroid>(); ClosestToCentroid intersectionPoint = new ClosestToCentroid(); ClosestToCentroid closest = new ClosestToCentroid(); closest.distance = 100000; //double distance = 100000; for (int i = 0; i < intersectionPoints.Count - 1; i++) { intersectionPoint.intersectionPoint = intersectionPoints[i]; intersectionPoint.distance = Math.Pow((Math.Pow((intersectionPoints[i].x - centroid.x), 2) + Math.Pow((intersectionPoints[i].y - centroid.y), 2)), 0.5); DistancesToCentroid.Add(intersectionPoint); } foreach (ClosestToCentroid dist in DistancesToCentroid) { if (dist.distance < closest.distance) { closest.distance = dist.distance; closest.intersectionPoint = dist.intersectionPoint; } } return(closest.intersectionPoint); }
/// <summary> /// Searches for the two closests points /// </summary> /// <param name="intersectionPoints">List of intersection points</param> /// <returns>The points that are closests to each other</returns> public static Point ShortestDistanceBetweenCutPoints(List<Point> intersectionPoints, Point centroid) { List<ClosestToCentroid> DistancesToCentroid = new List<ClosestToCentroid>(); ClosestToCentroid intersectionPoint = new ClosestToCentroid(); ClosestToCentroid closest = new ClosestToCentroid(); closest.distance = 100000; //double distance = 100000; for (int i = 0; i < intersectionPoints.Count - 1; i++) { intersectionPoint.intersectionPoint = intersectionPoints[i]; intersectionPoint.distance = Math.Pow((Math.Pow((intersectionPoints[i].x - centroid.x), 2) + Math.Pow((intersectionPoints[i].y - centroid.y), 2)), 0.5); DistancesToCentroid.Add(intersectionPoint); } foreach (ClosestToCentroid dist in DistancesToCentroid) { if (dist.distance < closest.distance) { closest.distance = dist.distance; closest.intersectionPoint = dist.intersectionPoint; } } return closest.intersectionPoint; }