private static DistanceBetweenCutpoints ShortestDistanceBetweenCutPoints(List <Point> CuttingPoints) { List <DistanceBetweenCutpoints> Distances = new List <DistanceBetweenCutpoints>(); DistanceBetweenCutpoints ShortestDistance = new DistanceBetweenCutpoints(); DistanceBetweenCutpoints Distance = new DistanceBetweenCutpoints(); ShortestDistance.distance = 100000; for (int i = 0; i < CuttingPoints.Count - 1; i++) { for (int j = i + 1; j < CuttingPoints.Count; j++) { Distance.point1 = CuttingPoints[i]; Distance.point2 = CuttingPoints[j]; Distance.distance = Math.Pow((Math.Pow((CuttingPoints[i].x - CuttingPoints[j].x), 2) + Math.Pow((CuttingPoints[i].y - CuttingPoints[j].y), 2)), 0.5); Distances.Add(Distance); } } foreach (DistanceBetweenCutpoints dist in Distances) { if (dist.distance < ShortestDistance.distance) { ShortestDistance.distance = dist.distance; ShortestDistance.point1 = dist.point1; ShortestDistance.point2 = dist.point2; } } return(ShortestDistance); }
private static Point Cluster(List <Point> CuttingPoints, int anchors) { //List<DistanceBetweenCutpoints> ListOfDistance = new List<DistanceBetweenCutpoints>(); //DistanceBetweenCutpoints cuts = new DistanceBetweenCutpoints(); Point centroid = new Point(); DistanceBetweenCutpoints shortest = new DistanceBetweenCutpoints(); //shortest.distance = 100000; while (CuttingPoints.Count != 0) { shortest = ShortestDistanceBetweenCutPoints(CuttingPoints); // get struct back centroid.x = (shortest.point1.x - shortest.point2.x) / 2; centroid.y = (shortest.point1.y - shortest.point2.y) / 2; CuttingPoints.Remove(shortest.point1); CuttingPoints.Remove(shortest.point2); CuttingPoints.Add(centroid); } return(centroid); }
private static Point Cluster(List<Point> CuttingPoints, int anchors) { //List<DistanceBetweenCutpoints> ListOfDistance = new List<DistanceBetweenCutpoints>(); //DistanceBetweenCutpoints cuts = new DistanceBetweenCutpoints(); Point centroid = new Point(); DistanceBetweenCutpoints shortest = new DistanceBetweenCutpoints(); //shortest.distance = 100000; while (CuttingPoints.Count != 0) { shortest = ShortestDistanceBetweenCutPoints(CuttingPoints); // get struct back centroid.x = (shortest.point1.x - shortest.point2.x) / 2; centroid.y = (shortest.point1.y - shortest.point2.y) / 2; CuttingPoints.Remove(shortest.point1); CuttingPoints.Remove(shortest.point2); CuttingPoints.Add(centroid); } return centroid; }
private static DistanceBetweenCutpoints ShortestDistanceBetweenCutPoints(List<Point> CuttingPoints) { List<DistanceBetweenCutpoints> Distances = new List<DistanceBetweenCutpoints>(); DistanceBetweenCutpoints ShortestDistance = new DistanceBetweenCutpoints(); DistanceBetweenCutpoints Distance = new DistanceBetweenCutpoints(); ShortestDistance.distance = 100000; for (int i = 0; i < CuttingPoints.Count - 1; i++) { for (int j = i + 1; j < CuttingPoints.Count; j++) { Distance.point1 = CuttingPoints[i]; Distance.point2 = CuttingPoints[j]; Distance.distance = Math.Pow((Math.Pow((CuttingPoints[i].x - CuttingPoints[j].x), 2) + Math.Pow((CuttingPoints[i].y - CuttingPoints[j].y), 2)), 0.5); Distances.Add(Distance); } } foreach (DistanceBetweenCutpoints dist in Distances) { if (dist.distance < ShortestDistance.distance) { ShortestDistance.distance = dist.distance; ShortestDistance.point1 = dist.point1; ShortestDistance.point2 = dist.point2; } } return ShortestDistance; }